Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
See: #1263
Looks like readwn changed its name yet again.
So, try using rule that examines site layout.
Hopefully not have to update quite so often.

Note, also cleaned up use of registerRule
  • Loading branch information
dteviot committed Mar 22, 2024
1 parent 8ae3ff8 commit 653dbab
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
6 changes: 2 additions & 4 deletions plugin/js/parsers/AdultfanfictionParser.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"use strict";

parserFactory.registerRule(
function(url) {
return AdultfanfictionParser.isAdultFanFiction(url) * 0.9;
},
function() { return new AdultfanfictionParser() }
(url) => AdultfanfictionParser.isAdultFanFiction(url) * 0.9,
() => new AdultfanfictionParser()
);

class AdultfanfictionParser extends Parser{
Expand Down
2 changes: 1 addition & 1 deletion plugin/js/parsers/BlogspotParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ parserFactory.registerRule(
return (util.extractHostName(url).indexOf(".blogspot.") != -1) ||
((BlogspotParser.findContentElement(dom) != null) * 0.5);
},
function() { return new BlogspotParser() }
() => new BlogspotParser()
);

parserFactory.registerManualSelect(
Expand Down
7 changes: 2 additions & 5 deletions plugin/js/parsers/MadaraParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ parserFactory.register("mangabob.com", function() { return new MadaraParser() })


parserFactory.registerRule(
// return probability (0.0 to 1.0) web page is a Madara Themed page
function(url, dom) {
return MadaraParser.isMadaraTheme(dom) * 0.6;
},
function() { return new MadaraParser() }
(url, dom) => MadaraParser.isMadaraTheme(dom) * 0.6,
() => new MadaraParser()
);

class MadaraParser extends WordpressBaseParser{
Expand Down
17 changes: 15 additions & 2 deletions plugin/js/parsers/ReadwnParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,21 @@ parserFactory.register("wuxiar.com", () => new ReadwnParser());
parserFactory.register("wuxiau.com", () => new ReadwnParser());
parserFactory.register("wuxiazone.com", () => new ReadwnParser());

parserFactory.registerRule(
(url, dom) => ReadwnParser.isReadwn(dom) * 0.8,
() => new ReadwnParser()
);

class ReadwnParser extends Parser{
constructor() {
super();
}

static isReadwn(dom) {
return (dom.querySelector(ReadwnParser.CoverSelector) !== null)
&& (dom.querySelector(ReadwnParser.AuthorSelector) !== null)
}

async getChapterUrls(dom, chapterUrlsUI) {
return this.getChapterUrlsFromMultipleTocPages(dom,
ReadwnParser.extractPartialChapterList,
Expand Down Expand Up @@ -77,7 +87,7 @@ class ReadwnParser extends Parser{
}

extractAuthor(dom) {
let authorLabel = dom.querySelector("span[itemprop='author']");
let authorLabel = dom.querySelector(ReadwnParser.AuthorSelector);
return authorLabel?.textContent ?? super.extractAuthor(dom);
}

Expand All @@ -91,10 +101,13 @@ class ReadwnParser extends Parser{
}

findCoverImageUrl(dom) {
return util.getFirstImgSrc(dom, "figure.cover");
return util.getFirstImgSrc(dom, ReadwnParser.CoverSelector);
}

getInformationEpubItemChildNodes(dom) {
return [...dom.querySelectorAll(".summary .content")];
}
}

ReadwnParser.CoverSelector = "figure.cover";
ReadwnParser.AuthorSelector = "span[itemprop='author']";
2 changes: 1 addition & 1 deletion plugin/js/parsers/WordpressBaseParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ parserFactory.registerRule(
return ((WordpressBaseParser.findContentElement(dom) != null) &&
(WordpressBaseParser.findChapterTitleElement(dom) != null)) * 0.5;
},
function() { return new WordpressBaseParser() }
() => new WordpressBaseParser()
);

parserFactory.registerManualSelect(
Expand Down

0 comments on commit 653dbab

Please sign in to comment.