use killer

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

当前为 2022-01-08 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        use killer
// @description "use" --> "use" (and other "use" 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);