utilise killer

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

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

You will need to install an extension such as Tampermonkey to install this script.

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

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

//matches "utilise" variants
var finder=/\butili[sz](?:e|ing)/gi;

function subFunc(s){
    //"utilise"-->"use"
    //preserves capitalisation
    //ASSUMES input is a "utilise" variant
    let res=s.replace(/^([uU])[^szSZ]*[sz](.*)$/,"$1s$2");//lowercase s/z
    if (res!=s){return res;}
    return s.replace(/^([uU])[^szSZ]*[SZ](.*)$/,"$1S$2");//uppercase s/z
}

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);