Skip to content

Commit

Permalink
Merge pull request #1526 from gamebeaker/improve-edit-chapter-URLs
Browse files Browse the repository at this point in the history
Improve edit chapter urls
  • Loading branch information
gamebeaker authored Sep 29, 2024
2 parents 37a1b9f + fe9f681 commit b898af2
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
4 changes: 4 additions & 0 deletions plugin/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 21 additions & 1 deletion plugin/js/ChapterUrlsUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,23 @@ class ChapterUrlsUI {
document.getElementById("coverUrlSection").hidden = !toTable;
document.getElementById("chapterSelectControlsDiv").hidden = !toTable;
ChapterUrlsUI.modifyApplyChangesButtons(button => button.hidden = toTable);
document.getElementById("editURLsHint").hidden = toTable;
}

/**
* @private
*/
setTableMode() {
try {
let chapters = this.htmlToChapters(ChapterUrlsUI.getEditChaptersUrlsInput().value);
let inputvalue = ChapterUrlsUI.getEditChaptersUrlsInput().value;
let chapters;
let lines = inputvalue.split("\n");
lines = lines.filter(a => a.trim() != "").map(a => a.trim());
if (URL.canParse(lines[0])) {
chapters = this.URLsToChapters(lines);
} else {
chapters = this.htmlToChapters(inputvalue);
}
this.parser.setPagesToFetch(chapters);
this.populateChapterUrlsTable(chapters);
this.usingTable = true;
Expand Down Expand Up @@ -318,6 +327,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()]);
Expand Down
1 change: 1 addition & 0 deletions plugin/js/DefaultParserUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 8 additions & 1 deletion plugin/js/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,19 @@ 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()));
content.insertBefore(titleElement, content.firstChild);
}
};
} else {
if (webPage.title == "[placeholder]") {
webPage.title = webPage.rawDom.title;
}
}
}

titleAlreadyPresent(title, content) {
Expand Down
1 change: 1 addition & 0 deletions plugin/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ <h3>Instructions</h3>
</div>
</div>
<button id="applyChangesButton" hidden>__MSG_button_Apply_Changes__</button>
<p id="editURLsHint" class="i18n" hidden>__MSG_label_Edit_URLs_Hint__</p>
<div id="findingChapterUrlsMessageRow" class="i18n warning">__MSG_Searching_For_URLs_Please_Wait__</div>
<table id="chapterUrlsTable" class="chapterlist">
<tr>
Expand Down

0 comments on commit b898af2

Please sign in to comment.