From df54d79099dcd98a16135a164448507133e641f3 Mon Sep 17 00:00:00 2001 From: dteviot Date: Sat, 9 Dec 2023 12:13:01 +1300 Subject: [PATCH] Add site https://boylove.cc/ See: https://github.com/dteviot/WebToEpub/issues/1104 --- plugin/js/Util.js | 5 ++-- plugin/js/parsers/BoyloveParser.js | 39 ++++++++++++++++++++++++++++++ plugin/popup.html | 1 + 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 plugin/js/parsers/BoyloveParser.js diff --git a/plugin/js/Util.js b/plugin/js/Util.js index d2603016..52dc50f3 100644 --- a/plugin/js/Util.js +++ b/plugin/js/Util.js @@ -430,9 +430,10 @@ var util = (function () { return (index === -1) ? null : uri.substring(index + 1); } - var resolveLazyLoadedImages = function(content, imgCss) { + var resolveLazyLoadedImages = function(content, imgCss, attrName) { + attrName = attrName || "data-src"; for(let img of content.querySelectorAll(imgCss)) { - let dataSrc = img.getAttribute("data-src"); + let dataSrc = img.getAttribute(attrName); if (dataSrc !== null) { img.src = dataSrc.trim(); } diff --git a/plugin/js/parsers/BoyloveParser.js b/plugin/js/parsers/BoyloveParser.js new file mode 100644 index 00000000..fb8c0ed4 --- /dev/null +++ b/plugin/js/parsers/BoyloveParser.js @@ -0,0 +1,39 @@ +"use strict"; + +parserFactory.register("boylove.cc", () => new BoyloveParser()); + +class BoyloveParser extends Parser{ + constructor() { + super(); + } + + async getChapterUrls(dom) { + return [...dom.querySelectorAll("ul#playlist__item_title_1_url li:not(.chapterOff) a")] + .map(a => util.hyperLinkToChapter(a)); + } + + findContent(dom) { + return dom.querySelector("section.reader-cartoon-chapter"); + } + + extractTitleImpl(dom) { + return dom.querySelector("div.stui-content div.title"); + } + + findChapterTitle(dom) { + return dom.querySelector("div.title"); + } + + findCoverImageUrl(dom) { + let div = dom.querySelector("div.stui-content__thumb [style*=background-image]"); + return "https://boylove.cc" + util.extractUrlFromBackgroundImage(div); + } + + preprocessRawDom(webPageDom) { + util.resolveLazyLoadedImages(webPageDom, "article img.lazy", "data-original"); + } + + getInformationEpubItemChildNodes(dom) { + return [...dom.querySelectorAll("p.desc")]; + } +} diff --git a/plugin/popup.html b/plugin/popup.html index ecef3eb4..5ee8f001 100644 --- a/plugin/popup.html +++ b/plugin/popup.html @@ -545,6 +545,7 @@

Instructions

+