Created
May 21, 2022 08:42
-
-
Save dkw72n/81f2235066883a426520444c12790546 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name bionify | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description yet another bionifier | |
// @author dkw72n | |
// @match *://*/* | |
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== | |
// @grant none | |
// @license MIT | |
// @run-at document-idle | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// bionifyPage(); | |
// bionifyPage2(); | |
function bionify(node) | |
{ | |
var a = Array.from(node.childNodes) | |
var n, b, cut, t, eol; | |
for (n of a){ | |
if (n.nodeName == '#text') { | |
while(true){ | |
var m = n.nodeValue.match(/[^-_a-zA-Z]+/) | |
if (m == null){ | |
break; | |
} else { | |
eol = false | |
cut = 0 | |
if (m.index > 0){ | |
// insert b | |
cut = 1 | |
if (m.index > 5) cut ++; | |
if (m.index > 8) cut ++; | |
if (m.index > 12) cut ++; | |
b = document.createElement('b') | |
b.textContent = n.nodeValue.slice(0, cut) | |
node.insertBefore(b, n) | |
} | |
if (m[0].length + m.index != n.nodeValue.length){ | |
// insert t | |
t = document.createTextNode(n.nodeValue.slice(cut, m.index + m[0].length)) | |
node.insertBefore(t, n) | |
cut = m.index + m[0].length | |
} else { | |
eol = true | |
} | |
if (cut > 0){ | |
n.data = n.data.slice(cut) | |
} | |
if (eol) break; | |
} | |
} | |
} else { | |
if (n.nodeName == 'CODE') continue; | |
if (n.nodeName == 'SCRIPT') continue; | |
if (n.nodeName == 'PRE') continue; | |
if (n.nodeName == 'A') continue; | |
if (n.nodeName == 'EM') continue; | |
if (n.nodeName == 'STYLE') continue; | |
if (n.nodeName == 'NOSCRIPT') continue; | |
if (n.nodeName == 'INPUT') continue; | |
if (n.nodeName.slice(0,1) == '#') continue; | |
bionify(n) | |
} | |
} | |
} | |
bionify(document.body) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment