Skip to content

Instantly share code, notes, and snippets.

@dkw72n
Created May 21, 2022 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkw72n/81f2235066883a426520444c12790546 to your computer and use it in GitHub Desktop.
Save dkw72n/81f2235066883a426520444c12790546 to your computer and use it in GitHub Desktop.
// ==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