From 1ba6463381f20465b912066445aae44dfc1a6413 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?JULI=CE=9BN=20=28Pinguin2001=29?= <75797743+Pinguin2001@users.noreply.github.com> Date: Tue, 24 Jan 2023 19:45:27 +0100 Subject: [PATCH] v1.0 --- simplyread-enhanced.js | 82 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 simplyread-enhanced.js diff --git a/simplyread-enhanced.js b/simplyread-enhanced.js new file mode 100644 index 0000000..532c428 --- /dev/null +++ b/simplyread-enhanced.js @@ -0,0 +1,82 @@ +/* See LICENSE file for copyright, license and warranty details. */ + +if(window.content && window.content.document && window.content.document.simplyread_original === undefined) window.content.document.simplyread_original = false; + +function simplyread(nostyle, nolinks) +{ + /* count the number of

tags that are direct children of parenttag */ + function count_p(parenttag) + { + var n = 0; + var c = parenttag.childNodes; + for (var i = 0; i < c.length; i++) { + if (c[i].tagName == "p" || c[i].tagName == "P") + n++; + } + return n; + } + + var doc; + doc = (document.body === undefined) + ? window.content.document : document; + + /* if simplyread_original is set, then the simplyread version is currently active, + * so switch to the simplyread_original html */ + if (doc.simplyread_original) { + doc.body.innerHTML = doc.simplyread_original; + for (var i = 0; i < doc.styleSheets.length; i++) + doc.styleSheets[i].disabled = false; + doc.simplyread_original = false + return 0; + } + + doc.simplyread_original = doc.body.innerHTML; + doc.body.innerHTML = doc.body.innerHTML.replace(/]*>\s*]*>/g, "

"); + + var biggest_num = 0; + var biggest_tag; + + /* search for tag with most direct children

tags */ + var t = doc.getElementsByTagName("*"); + for (var i = 0; i < t.length; i++) { + var p_num = count_p(t[i]); + if (p_num > biggest_num) { + biggest_num = p_num; + biggest_tag = t[i]; + } + } + + if (biggest_num == 0) return 1; + + /* save and sanitise content of chosen tag */ + var fresh = doc.createElement("div"); + fresh.innerHTML = biggest_tag.innerHTML; + fresh.innerHTML = fresh.innerHTML.replace(/<\/?font[^>]*>/g, ""); + fresh.innerHTML = fresh.innerHTML.replace(/style="[^"]*"/g, ""); + if(nolinks) + fresh.innerHTML = fresh.innerHTML.replace(/<\/?a[^>]*>/g, ""); + fresh.innerHTML = fresh.innerHTML.replace(/<\/?span[^>]*>/g, ""); + fresh.innerHTML = fresh.innerHTML.replace(/]*>/g, "" + + "

" + "

"+doc.title+"

" + fresh.innerHTML + "
"; + + return 0; +} + +simplyread(); \ No newline at end of file