utilise killer

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

  1. // ==UserScript==
  2. // @name utilise killer
  3. // @description "utilise" --> "use" (and other "utilise" variants)
  4. // @include http://*/*
  5. // @include https://*/*
  6. // @version 2.1
  7. // @license MIT
  8. // @grant none
  9. // @run-at document-idle
  10. // @namespace https://greasyfork.org/users/730393
  11. // ==/UserScript==
  12.  
  13. //matches "utilise" variants
  14. var finder=/\butili[sz](?:e|ing)/gi;
  15.  
  16. function subFunc(s){
  17. //"utilise"-->"use"
  18. //preserves capitalisation
  19. //ASSUMES input is a "utilise" variant
  20. let res=s.replace(/^([uU])[^szSZ]*[sz](.*)$/,"$1s$2");//lowercase s/z
  21. if (res!=s){return res;}
  22. return s.replace(/^([uU])[^szSZ]*[SZ](.*)$/,"$1S$2");//uppercase s/z
  23. }
  24.  
  25. function substituteText(text){return text.replace(finder, subFunc);}
  26.  
  27. function doSubstitutions(){
  28. var textNodes = document.evaluate("//text()", document.body, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  29. for (var i = 0; i < textNodes.snapshotLength; i++) {
  30. var node = textNodes.snapshotItem(i);
  31. //apparently rewriting all the nodes with the same thing breaks some websites(eg:twitter)
  32. //calculate before/after
  33. var data=node.data;
  34. var new_data=substituteText(node.data);
  35. //replace if needed
  36. if (data!=new_data){node.data=new_data;}
  37. }
  38. }
  39.  
  40. //at idle
  41. doSubstitutions()
  42. //repeat after 1s
  43. setTimeout(doSubstitutions,1000);