Lurker News

Comments (271) 94 threads

Show all comments

Showing thread 6 of 94

phpnode1 reply#
Cool, here's a quick hack to try a similar technique with the comments in this thread (copy and paste into dev tools:

    $$('span.commtext').forEach(span => {
        const frag = document.createDocumentFragment();
        span.textContent.split(/\s+/).forEach(word => {
          const len = Math.ceil(word.length * 0.3);
          const leading = document.createElement('strong');
          leading.textContent = word.slice(0, len);
          const trailing = document.createTextNode(word.slice(len) + ' ');
          frag.appendChild(leading);
          frag.appendChild(trailing);
        });
        span.parentNode.replaceChild(frag, span);
    })
hexomancer2 replies#
I made a version which works in all web pages, it is still very hacky though:

    function bionifyPage(){
        function bionifyWord(word) {
            if (word.length == 1) {
                return word;
            }
            var numBold = Math.ceil(word.length * 0.3);

            // return "" + word.slice(0, numBold) + "" +  + "" + word.slice(numBold) + "";
            return "" + word.slice(0, numBold) + "" + "" + word.slice(numBold) + "";
        }

        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);
    }
phpnode1 reply#
I think yours infringes the patent ;)
hexomancer2 replies#
Alright, I modified it to be like the original comment.

Continue this thread — 2 replies

w-m1 reply#
Could you make one that reduces the opacity of the second half of the word, while keeping the same boldness for the complete text, to compare the effect?
hexomancer#
I have made a chrome extension that does that: https://github.com/ahrm/chrome-fastread

You can customize the css attributes of highlighted text and rest of the word using the two input texts.