Skip to content

Commit 2a4e735

Browse files
authored
Merge pull request #2299 from X2E4VXpZKv/ExperimentalTabMode
Scribblehub parser improvements
2 parents b85f03c + 61fa9bd commit 2a4e735

File tree

3 files changed

+72
-5
lines changed

3 files changed

+72
-5
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@
9494
{ "name": "Yomafil"},
9595
{ "name": "Varun Patkar", "email": "[email protected]" },
9696
{ "name": "Peter Kaufman", "email": "[email protected]" },
97-
{ "name": "MD Shabrez" }
97+
{ "name": "MD Shabrez" },
98+
{ "name": "X2E4VXpZKv" }
9899
],
99100
"license": "GPL-3.0-only",
100101
"bugs": {

plugin/js/parsers/ScribblehubParser.js

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,17 @@ class ScribblehubParser extends Parser {
6060
let tags = [...dom.querySelectorAll(selector)];
6161
return tags.map(e => e.textContent.trim()).join(", ");
6262
}
63-
63+
6464
extractDescription(dom) {
65-
return dom.querySelector("div [property='description']").textContent.trim();
65+
return this.extractDescriptionInternal(dom).innerText.trim();
66+
}
67+
// unwrap the description from the readmore that you may get on mobile
68+
extractDescriptionInternal(dom) {
69+
let desc = dom.querySelector(".wi_fic_desc");
70+
desc.querySelectorAll(".dots, .morelink").forEach(e => e.remove());
71+
desc.querySelectorAll(".testhide").forEach(e => e.replaceWith(...e.childNodes));
72+
73+
return desc;
6674
}
6775

6876
findChapterTitle(dom) {
@@ -74,10 +82,67 @@ class ScribblehubParser extends Parser {
7482
}
7583

7684
preprocessRawDom(webPageDom) {
77-
this.tagAuthorNotesBySelector(webPageDom, ".wi_authornotes", ".wi_news");
85+
let content = this.findContent(webPageDom);
86+
87+
this.tagAuthorNotesBySelector(content, ".wi_authornotes, .wi_news");
88+
89+
// spoilers
90+
for (let element of content.querySelectorAll(".sp-wrap")) {
91+
element.querySelector(".sp-body>.spdiv").remove();
92+
93+
let details = webPageDom.createElement("details");
94+
let summary = webPageDom.createElement("summary");
95+
summary.append(...element.querySelector(".sp-head").childNodes);
96+
details.append(summary);
97+
details.append(...element.querySelector(".sp-body").childNodes);
98+
99+
element.replaceWith(details);
100+
}
101+
102+
// anouncements
103+
for (let element of content.querySelectorAll(".wi_news_title")) {
104+
element.setAttribute("style", "font-weight: bold");
105+
element.querySelector(".fa-exclamation-triangle").replaceWith("⚠");
106+
}
107+
108+
// author notes
109+
for (let element of content.querySelectorAll(".p-avatar-wrap")) {
110+
element.remove();
111+
}
112+
78113
}
79114

80115
getInformationEpubItemChildNodes(dom) {
81-
return [...dom.querySelectorAll("div.fic_row.details")];
116+
function cleanTag(tag, index, array) {
117+
let out = tag.ownerDocument.createElement("a");
118+
out.setAttribute("href", tag.getAttribute("href"));
119+
out.innerText = tag.innerText;
120+
return index < array.length -1 ? [out, ", "] : [out];
121+
}
122+
123+
let info = [];
124+
125+
info.push(dom.createElement("div").innerHTML = "<p><b>Synopsis</b></p>");
126+
info.push(...this.extractDescriptionInternal(dom).childNodes);
127+
128+
let genre = dom.querySelectorAll(".wi_fic_genre a.fic_genre");
129+
if (genre.length > 0) {
130+
info.push(dom.createElement("div").innerHTML = "<p><b>Genre</b></p>");
131+
info.push(...[...genre].flatMap(cleanTag));
132+
}
133+
134+
let fandom = dom.querySelectorAll(".wi_fic_genre a.stag");
135+
if (fandom.length > 0) {
136+
info.push(dom.createElement("div").innerHTML = "<p><b>Fandom</b></p>");
137+
info.push(...[...fandom].flatMap(cleanTag));
138+
}
139+
140+
let tags = dom.querySelectorAll(".wi_fic_showtags a.stag");
141+
if (tags.length > 0) {
142+
info.push(dom.createElement("div").innerHTML = "<p><b>Tags</b></p>");
143+
info.push(...[...tags].flatMap(cleanTag));
144+
}
145+
146+
return info;
82147
}
83148
}

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,7 @@ Don't forget to give the project a star! Thanks again!
804804
<li>Varun Patkar</li>
805805
<li>Peter Kaufman</li>
806806
<li>MD Shabrez</li>
807+
<li>X2E4VXpZKv</li>
807808
</ul>
808809
</details>
809810

0 commit comments

Comments
 (0)