utilise killer

"utilise" --> "use" (and other "utilise" variants)

目前為 2022-01-08 提交的版本,檢視 最新版本

// ==UserScript==
// @name        utilise killer
// @description "utilise" --> "use" (and other "utilise" variants)
// @include     http://*/*
// @include     https://*/*
// @version     2
// @license MIT
// @grant       none
// @namespace https://greasyfork.org/users/730393
// ==/UserScript==


//finder regex matches any occurence of the annoyance
var finder=new RegExp("\\butili[sz](?:e|ing)",'gi');

var subFunc;
(function (){
    //removes the "tili" and does z-->s if needed (U)tili(S)(*)--> (U)(S)(*)
    //r1 vs r2 match for capitalisation of the S or Z
    let r1=new RegExp("^([uU])[^szSZ]*[sz](.*)$")
    let r2=new RegExp("^([uU])[^szSZ]*[SZ](.*)$")
    subFunc=(function(s){
        let res=s.replace(r1,"$1s$2");
        if (res!=s){return res;}
        return s.replace(r2,"$1S$2");
    });
})();

function substituteText(text){return text.replace(finder, subFunc);}

function doSubstitutions(){
    var textNodes = document.evaluate("//text()", document.body, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
    for (var i = 0; i < textNodes.snapshotLength; i++) {
        var node = textNodes.snapshotItem(i);
        //apparently rewriting all the nodes with the same thing breaks some websites(eg:twitter)
        //calculate before/after
        var data=node.data;
        var new_data=substituteText(node.data);
        //replace if needed
        if (data!=new_data){node.data=new_data;}
    }
}

//at idle
doSubstitutions()
//repeat after 1s
setTimeout(doSubstitutions,1000);