From 1c3b6a401276be2c97251c4b48b3c123891e3dfe Mon Sep 17 00:00:00 2001 From: dteviot Date: Wed, 24 Jan 2024 20:36:03 +1300 Subject: [PATCH] Remove theft message from RoyalRoad See: https://github.com/dteviot/WebToEpub/issues/1177 --- plugin/js/parsers/RoyalRoadParser.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/plugin/js/parsers/RoyalRoadParser.js b/plugin/js/parsers/RoyalRoadParser.js index d528e28b..405e3258 100644 --- a/plugin/js/parsers/RoyalRoadParser.js +++ b/plugin/js/parsers/RoyalRoadParser.js @@ -37,6 +37,26 @@ class RoyalRoadParser extends Parser{ document.getElementById("removeAuthorNotesRow").hidden = false; } + preprocessRawDom(webPageDom) { + this.removeWatermarks(webPageDom); + } + + //watermarks are regular

elements set to "display: none" by internal css + removeWatermarks(webPageDom) { + let internalStyles = [...webPageDom.querySelectorAll("style")] + .map(style => style.sheet?.rules); + let allCssRules = []; + for(let ruleList of internalStyles) { + for(let rule of ruleList) { + allCssRules.push(rule); + } + } + for(let rule of allCssRules.filter(s => s.style.display == "none")) { + console.log(webPageDom.querySelector(rule.selectorText).textContent); + webPageDom.querySelector(rule.selectorText)?.remove(); + } + } + removeUnwantedElementsFromContentElement(content) { // only keep the