diff --git a/plugin/js/Util.js b/plugin/js/Util.js index 7d002984..5051f324 100644 --- a/plugin/js/Util.js +++ b/plugin/js/Util.js @@ -742,8 +742,8 @@ var util = (function () { var safeForFileName = function (title, maxLength = 20) { if(title) { - // Allow only a-z regardless of case and numbers as well as hyphens and underscores; replace spaces with underscores - title = title.replace(/ /gi, "_").replace(/([^a-z0-9_-]+)/gi, ""); + // Allow only a-z regardless of case and numbers as well as hyphens and underscores; replace spaces and no-break spaces with underscores + title = title.replace(/ ||\u00a0/gi, "_").replace(/([^a-z0-9_-]+)/gi, ""); // There is technically a 255 character limit in windows for file paths. // So we will allow files to have 20 characters and when they go over we split them // we then truncate the middle so that the file name is always different diff --git a/plugin/js/parsers/QuestionableQuestingParser.js b/plugin/js/parsers/QuestionableQuestingParser.js deleted file mode 100644 index e38d4d85..00000000 --- a/plugin/js/parsers/QuestionableQuestingParser.js +++ /dev/null @@ -1,117 +0,0 @@ -"use strict"; - -parserFactory.register("forum.questionablequesting.com", () => new QuestionableQuestingParser()); -parserFactory.register("questionablequesting.com", () => new QuestionableQuestingParser()); - -class QuestionableQuestingParser extends Parser{ - constructor() { - super(); - this.cache = new FetchCache(); - } - - clampSimultanousFetchSize() { - return 1; - } - - async getChapterUrls(dom) { - let chapters = [...dom.querySelectorAll("div.threadmarkList a.PreviewTooltip")] - .map(a => this.linkToChapter(a)); - this.addAnchorToFirstChapter(chapters, dom); - return chapters; - }; - - addAnchorToFirstChapter(chapters, dom) { - if (chapters.length == 0) { - return; - } - let first = chapters[0]; - let url = new URL(first.sourceUrl); - if (url.hash == "") { - let message = dom.querySelector("li.message"); - if (message != null) { - url.hash = "#" + message.id; - first.sourceUrl = url.href; - } - } - } - - linkToChapter(link) { - let cleanUrl = new URL(link.href); - let path = cleanUrl.pathname.split("/").slice(3, 6).join("/"); - cleanUrl.pathname = path; - return { - sourceUrl: cleanUrl.href, - title: link.innerText.trim(), - newArc: null - }; - } - - findContent(dom) { - return Parser.findConstrutedContent(dom); - }; - - extractTitleImpl(dom) { - return dom.querySelector("div.titleBar h1"); - }; - - extractAuthor(dom) { - let authorLabel = dom.querySelector("a.username"); - return (authorLabel === null) ? super.extractAuthor(dom) : authorLabel.textContent; - }; - - async fetchChapter(url) { - let fetchedDom = await this.cache.fetch(url); - let newDoc = Parser.makeEmptyDocForContent(url); - let id = (new URL(url)).hash.substring(1); - let post = fetchedDom.getElementById(id); - let content = post.querySelector("article"); - this.addTitleToChapter(newDoc, post); - this.removeBlockquotes(content); - this.fixupImageUrls(content); - newDoc.content.appendChild(content); - return newDoc.dom; - } - - fixupImageUrls(content) { - for(let i of content.querySelectorAll("img")) { - let dataUrl = i.getAttribute("data-url"); - if (dataUrl && (i.src !== dataUrl)) { - i.src = dataUrl; - i.removeAttribute("data-url"); - i.removeAttribute("data-src"); - } - this.cleanupMangledImageSrc(i); - } - } - - cleanupMangledImageSrc(img) { - let url = new URL(img.src); - let hostname = url.hostname; - if (hostname.includes("questionablequesting")) { - let path = url.pathname; - let index = path.indexOf("/proxy.php"); - if (0 < index) { - url.pathname = path.substring(index); - } - img.src = url; - } - } - - addTitleToChapter(newDoc, post) { - let titleElement = post.querySelector("span.label"); - let strong = titleElement.querySelector("strong"); - if (strong !== null) { - strong.remove(); - } - let title = newDoc.dom.createElement("h1"); - title.textContent = titleElement.textContent.trim(); - newDoc.content.appendChild(title); - } - - removeBlockquotes(content) { - let blocks = [...content.querySelectorAll("blockquote")]; - for(let block of blocks) { - block.replaceWith(...block.childNodes); - } - } -} diff --git a/plugin/js/parsers/SpacebattlesParser.js b/plugin/js/parsers/SpacebattlesParser.js index c6a19463..50abcd83 100644 --- a/plugin/js/parsers/SpacebattlesParser.js +++ b/plugin/js/parsers/SpacebattlesParser.js @@ -3,6 +3,8 @@ parserFactory.register("forums.spacebattles.com", () => new SpacebattlesParser()); parserFactory.register("forums.sufficientvelocity.com", () => new SpacebattlesParser()); parserFactory.register("alternatehistory.com", () => new SpacebattlesParser()); +parserFactory.register("forum.questionablequesting.com", () => new SpacebattlesParser()); +parserFactory.register("questionablequesting.com", () => new SpacebattlesParser()); class SpacebattlesParser extends Parser{ constructor() { diff --git a/plugin/popup.html b/plugin/popup.html index 15104b2e..ca5b8b49 100644 --- a/plugin/popup.html +++ b/plugin/popup.html @@ -695,7 +695,6 @@