vdotfiles

Cem's Dotfiles for Void Linux
git clone git://git.ckyln.com/vdotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

commit 739868f156464cb9382e3583c1f5abd14bf5cfcd
parent 76bc62d52b175ef9f70b521682916e8941e9fb52
Author: Cem Keylan <cem@ckyln.com>
Date:   Sun, 24 Nov 2019 23:13:28 +0300

add .surf directory

Diffstat:
A.surf/script.js | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A.surf/styles/default.css | 19+++++++++++++++++++
2 files changed, 109 insertions(+), 0 deletions(-)

diff --git a/.surf/script.js b/.surf/script.js @@ -0,0 +1,90 @@ +/* See COPYING file for copyright, license and warranty details. */ + +(function() { + document.addEventListener('keydown', keybind, false); +})(); + +function keybind(e) { + if(e.altKey && String.fromCharCode(e.keyCode) == "R") + simplyread(); +} +/* See COPYING 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 <p> 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(/<br[^>]*>\s*<br[^>]*>/g, "<p>"); + + var biggest_num = 0; + var biggest_tag; + + /* search for tag with most direct children <p> 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(/<style[^>]*>/g, "<style media=\"aural\">"); /* ensures contents of style tag are ignored */ + + for (var i = 0; i < doc.styleSheets.length; i++) + doc.styleSheets[i].disabled = true; + + srstyle = + "p{margin:0ex auto;} h1,h2,h3,h4{font-weight:normal}" + + "p+p{text-indent:2em;} body{background:#cccccc none}" + + "img{display:block; max-width: 32em; padding:1em; margin: auto}" + + "h1{text-align:center;text-transform:uppercase}" + + "div#sr{width:34em; padding:8em; padding-top:2em;" + + " background-color:white; margin:auto; line-height:1.4;" + + " text-align:justify; font-family:serif; hyphens:auto;}"; + /* text-rendering:optimizeLegibility; - someday this will work, + * but at present it just ruins justify, so is disabled */ + + doc.body.innerHTML = + "<style type=\"text/css\">" + (nostyle ? "" : srstyle) + "</style>" + + "<div id=\"sr\">" + "<h1>"+doc.title+"</h1>" + fresh.innerHTML + "</div>"; + + return 0; +} diff --git a/.surf/styles/default.css b/.surf/styles/default.css @@ -0,0 +1,19 @@ +/*pre,textarea,body,input,td,tr,p {*/ + /*background-color: black !important;*/ + /*background-image: none !important;*/ + /*color: #e0e0e0 !important;*/ +/*}*/ +/*div {*/ + /*background-color: #202020 !important;*/ + /*background-image: none !important;*/ + /*color: #e0e0e0 !important;*/ +/*}*/ +/*h1,h2,h3,h4 {*/ + /*background-color: black !important;*/ + /*color: #e02020 !important;*/ +/*}*/ +/*a {*/ + /*color: #5050f0 !important;*/ +/*}*/ +html { background-color: white; color: black; } +pre,textarea,body,input,td,tr,p { color: black; }