Skip to content

Commit

Permalink
Remove theft message from RoyalRoad
Browse files Browse the repository at this point in the history
See: #1177
  • Loading branch information
dteviot committed Jan 24, 2024
1 parent 6551e1a commit 1c3b6a4
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions plugin/js/parsers/RoyalRoadParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ class RoyalRoadParser extends Parser{
document.getElementById("removeAuthorNotesRow").hidden = false;
}

preprocessRawDom(webPageDom) {
this.removeWatermarks(webPageDom);
}

//watermarks are regular <p> 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 <div class="chapter-inner" elements of content
for(let i = content.childElementCount - 1; 0 <= i; --i) {
Expand Down

0 comments on commit 1c3b6a4

Please sign in to comment.