From a752c1c0f119ec5a134aebc8ad4ec1423094738b Mon Sep 17 00:00:00 2001 From: gamebeaker Date: Sat, 28 Sep 2024 23:15:35 +0200 Subject: [PATCH 1/8] implement [placeholder] title --- plugin/js/Parser.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugin/js/Parser.js b/plugin/js/Parser.js index cd109c4e..a2bf3ce7 100644 --- a/plugin/js/Parser.js +++ b/plugin/js/Parser.js @@ -112,6 +112,9 @@ class Parser { if (title instanceof HTMLElement) { title = title.textContent; } + if (webPage.title == "[placeholder]") { + webPage.title = title.trim(); + } if (!this.titleAlreadyPresent(title, content)) { let titleElement = webPage.rawDom.createElement("h1"); titleElement.appendChild(webPage.rawDom.createTextNode(title.trim())); From 0458fc3b55eb34d82e6b0379127766e7baa429f3 Mon Sep 17 00:00:00 2001 From: gamebeaker Date: Sat, 28 Sep 2024 23:39:54 +0200 Subject: [PATCH 2/8] convert URLsToChapters --- plugin/js/ChapterUrlsUI.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/plugin/js/ChapterUrlsUI.js b/plugin/js/ChapterUrlsUI.js index cd8eaee0..59d70032 100644 --- a/plugin/js/ChapterUrlsUI.js +++ b/plugin/js/ChapterUrlsUI.js @@ -287,7 +287,15 @@ class ChapterUrlsUI { */ setTableMode() { try { - let chapters = this.htmlToChapters(ChapterUrlsUI.getEditChaptersUrlsInput().value); + let inputvalue = ChapterUrlsUI.getEditChaptersUrlsInput().value; + let chapters; + let lines = inputvalue.split('\n'); + if (URL.canParse(lines[0])) { + lines = lines.filter(function(line) { return line.trim() != ''; }); + chapters = this.URLsToChapters(lines); + } else { + chapters = this.htmlToChapters(inputvalue); + } this.parser.setPagesToFetch(chapters); this.populateChapterUrlsTable(chapters); this.usingTable = true; @@ -318,6 +326,17 @@ class ChapterUrlsUI { return [...doc.body.querySelectorAll("a")].map(a => util.hyperLinkToChapter(a)); } + /** + * @private + */ + URLsToChapters(URLs) { + let returnchapters = URLs.map(e => ({ + sourceUrl: e, + title: `[placeholder]` + })); + return returnchapters; + } + /** @private */ copyUrlsToClipboard() { let text = this.chaptersToHTML([...this.parser.getPagesToFetch().values()]); From 3562ce370d9537f4ac3d7f67774de5fe60c97811 Mon Sep 17 00:00:00 2001 From: gamebeaker Date: Sat, 28 Sep 2024 23:44:01 +0200 Subject: [PATCH 3/8] use dom.title if findChapterTitle()=null --- plugin/js/Parser.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugin/js/Parser.js b/plugin/js/Parser.js index a2bf3ce7..fc656b36 100644 --- a/plugin/js/Parser.js +++ b/plugin/js/Parser.js @@ -108,13 +108,17 @@ class Parser { addTitleToContent(webPage, content) { let title = this.findChapterTitle(webPage.rawDom, webPage); + if (webPage.title == "[placeholder]") { + if (title != null) { + webPage.title = title.trim(); + } else { + webPage.title = webPage.rawDom.title; + } + } if (title != null) { if (title instanceof HTMLElement) { title = title.textContent; } - if (webPage.title == "[placeholder]") { - webPage.title = title.trim(); - } if (!this.titleAlreadyPresent(title, content)) { let titleElement = webPage.rawDom.createElement("h1"); titleElement.appendChild(webPage.rawDom.createTextNode(title.trim())); From a1a0f0261170af85a900cfbfac402b520d4cb3ab Mon Sep 17 00:00:00 2001 From: gamebeaker Date: Sat, 28 Sep 2024 23:52:19 +0200 Subject: [PATCH 4/8] fix dom.title if findChapterTitle()=null --- plugin/js/Parser.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/plugin/js/Parser.js b/plugin/js/Parser.js index fc656b36..40e903d9 100644 --- a/plugin/js/Parser.js +++ b/plugin/js/Parser.js @@ -108,23 +108,23 @@ class Parser { addTitleToContent(webPage, content) { let title = this.findChapterTitle(webPage.rawDom, webPage); - if (webPage.title == "[placeholder]") { - if (title != null) { - webPage.title = title.trim(); - } else { - webPage.title = webPage.rawDom.title; - } - } if (title != null) { if (title instanceof HTMLElement) { title = title.textContent; } + if (webPage.title == "[placeholder]") { + webPage.title = title.trim(); + } if (!this.titleAlreadyPresent(title, content)) { let titleElement = webPage.rawDom.createElement("h1"); titleElement.appendChild(webPage.rawDom.createTextNode(title.trim())); content.insertBefore(titleElement, content.firstChild); } - }; + } else { + if (webPage.title == "[placeholder]") { + webPage.title = webPage.rawDom.title; + } + } } titleAlreadyPresent(title, content) { From d52d6b0754900c0e795ec73d37e737b4bfa70b1d Mon Sep 17 00:00:00 2001 From: gamebeaker Date: Sun, 29 Sep 2024 00:03:46 +0200 Subject: [PATCH 5/8] fix eslint --- plugin/js/ChapterUrlsUI.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin/js/ChapterUrlsUI.js b/plugin/js/ChapterUrlsUI.js index 59d70032..835c9c30 100644 --- a/plugin/js/ChapterUrlsUI.js +++ b/plugin/js/ChapterUrlsUI.js @@ -289,9 +289,9 @@ class ChapterUrlsUI { try { let inputvalue = ChapterUrlsUI.getEditChaptersUrlsInput().value; let chapters; - let lines = inputvalue.split('\n'); + let lines = inputvalue.split("\n"); if (URL.canParse(lines[0])) { - lines = lines.filter(function(line) { return line.trim() != ''; }); + lines = lines.filter(function(line) { return line.trim() != ""; }); chapters = this.URLsToChapters(lines); } else { chapters = this.htmlToChapters(inputvalue); @@ -332,7 +332,7 @@ class ChapterUrlsUI { URLsToChapters(URLs) { let returnchapters = URLs.map(e => ({ sourceUrl: e, - title: `[placeholder]` + title: "[placeholder]" })); return returnchapters; } From 1b7b02068bfa6a6bfbbcfd7c6e47571425eceba4 Mon Sep 17 00:00:00 2001 From: gamebeaker Date: Sun, 29 Sep 2024 00:06:48 +0200 Subject: [PATCH 6/8] fix first line empty URLs list --- plugin/js/ChapterUrlsUI.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/js/ChapterUrlsUI.js b/plugin/js/ChapterUrlsUI.js index 835c9c30..23b450d1 100644 --- a/plugin/js/ChapterUrlsUI.js +++ b/plugin/js/ChapterUrlsUI.js @@ -290,8 +290,8 @@ class ChapterUrlsUI { let inputvalue = ChapterUrlsUI.getEditChaptersUrlsInput().value; let chapters; let lines = inputvalue.split("\n"); + lines = lines.filter(function(line) { return line.trim() != ""; }); if (URL.canParse(lines[0])) { - lines = lines.filter(function(line) { return line.trim() != ""; }); chapters = this.URLsToChapters(lines); } else { chapters = this.htmlToChapters(inputvalue); From 00d2df71e77d4f39880c3d2715d951f3bad85444 Mon Sep 17 00:00:00 2001 From: gamebeaker Date: Sun, 29 Sep 2024 00:12:07 +0200 Subject: [PATCH 7/8] fix spaces/tabs in URLs list --- plugin/js/ChapterUrlsUI.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/js/ChapterUrlsUI.js b/plugin/js/ChapterUrlsUI.js index 23b450d1..f0c05652 100644 --- a/plugin/js/ChapterUrlsUI.js +++ b/plugin/js/ChapterUrlsUI.js @@ -290,7 +290,7 @@ class ChapterUrlsUI { let inputvalue = ChapterUrlsUI.getEditChaptersUrlsInput().value; let chapters; let lines = inputvalue.split("\n"); - lines = lines.filter(function(line) { return line.trim() != ""; }); + lines = lines.filter(a => a.trim() != "").map(a => a.trim()); if (URL.canParse(lines[0])) { chapters = this.URLsToChapters(lines); } else { From fe9f6817e49606278567d5debd00776edf6906aa Mon Sep 17 00:00:00 2001 From: gamebeaker Date: Sun, 29 Sep 2024 16:47:04 +0200 Subject: [PATCH 8/8] Add hint message --- plugin/_locales/en/messages.json | 4 ++++ plugin/js/ChapterUrlsUI.js | 1 + plugin/js/DefaultParserUI.js | 1 + plugin/popup.html | 1 + 4 files changed, 7 insertions(+) diff --git a/plugin/_locales/en/messages.json b/plugin/_locales/en/messages.json index 5ea8862e..f623c7e7 100644 --- a/plugin/_locales/en/messages.json +++ b/plugin/_locales/en/messages.json @@ -255,6 +255,10 @@ "message": "CSS selector for element(s) to remove:", "description": "Label in front input for CCS selector for elements to remove" }, + "__MSG_label_Edit_URLs_Hint__": { + "message": "You can edit the URLs in html format or as a simle URL list (one URL per line).", + "description": "Label in Edit Chapter URLs to help the user." + }, "__MSG_label_Element_With_Chapter_Content__": { "message": "Element with Chapter Content:", "description": "Label in front input for type of element holding each chapter's content" diff --git a/plugin/js/ChapterUrlsUI.js b/plugin/js/ChapterUrlsUI.js index f0c05652..af61518f 100644 --- a/plugin/js/ChapterUrlsUI.js +++ b/plugin/js/ChapterUrlsUI.js @@ -280,6 +280,7 @@ class ChapterUrlsUI { document.getElementById("coverUrlSection").hidden = !toTable; document.getElementById("chapterSelectControlsDiv").hidden = !toTable; ChapterUrlsUI.modifyApplyChangesButtons(button => button.hidden = toTable); + document.getElementById("editURLsHint").hidden = toTable; } /** diff --git a/plugin/js/DefaultParserUI.js b/plugin/js/DefaultParserUI.js index b7f4335b..a82a5963 100644 --- a/plugin/js/DefaultParserUI.js +++ b/plugin/js/DefaultParserUI.js @@ -133,6 +133,7 @@ class DefaultParserUI { if (isVisible) { ChapterUrlsUI.getEditChaptersUrlsInput().hidden = true; ChapterUrlsUI.modifyApplyChangesButtons(button => button.hidden = true); + document.getElementById("editURLsHint").hidden = true; } document.getElementById("defaultParserSection").hidden = !isVisible; } diff --git a/plugin/popup.html b/plugin/popup.html index 86419990..810d1a51 100644 --- a/plugin/popup.html +++ b/plugin/popup.html @@ -490,6 +490,7 @@

Instructions

+
__MSG_Searching_For_URLs_Please_Wait__