-
-
Save delijati/d079664056113b48a8a2d9ae1abc8764 to your computer and use it in GitHub Desktop.
bio
This file contains hidden or 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
function bionifyPage(){ | |
function bionifyWord(word) { | |
if (word.length == 1) { | |
return word; | |
} | |
var numBold = Math.ceil(word.length * 0.3); | |
// return "<div class=\"bionic-highlight\">" + word.slice(0, numBold) + "</div>" + + "<div class=\"bionic-rest\">" + word.slice(numBold) + "</div>"; | |
return "<b>" + word.slice(0, numBold) + "</b>" + "<span>" + word.slice(numBold) + "</span>"; | |
} | |
function bionifyText(text) { | |
var res = ""; | |
if (text.length < 10) { | |
return text; | |
} | |
for (var word of text.split(" ")) { | |
res += bionifyWord(word) + " "; | |
} | |
return res; | |
} | |
function bionifyNode(node) { | |
if (node.tagName == 'SCRIPT') return; | |
if ((node.childNodes == undefined) || (node.childNodes.length == 0)) { | |
if ((node.textContent != undefined) && (node.tagName == undefined)) { | |
var newNode = document.createElement('span'); | |
var bionifiedText = bionifyText(node.textContent) | |
newNode.innerHTML = bionifiedText; | |
if (node.textContent.length > 20){ | |
node.replaceWith(newNode); | |
} | |
} | |
} | |
else { | |
for (var child of node.childNodes) { | |
bionifyNode(child); | |
} | |
} | |
} | |
bionifyNode(document.body); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment