Skip to content

Instantly share code, notes, and snippets.

@cking
Last active July 31, 2025 07:01
Show Gist options
  • Select an option

  • Save cking/d63ec8fd1eb48a937588f16c43f74cc5 to your computer and use it in GitHub Desktop.

Select an option

Save cking/d63ec8fd1eb48a937588f16c43f74cc5 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name AI
// @namespace z0ne
// @match *://*/*
// @version 1.1
// @downloadURL https://gist.github.com/cking/d63ec8fd1eb48a937588f16c43f74cc5/raw/f1bc1d91706dca7bcf41d37c2529e6296353b2ad/ai.user.js
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_registerMenuCommand
// @author KuraBloodlust
// @description 7/31/2025, 8:26:23 AM
// @run-at document-end
// ==/UserScript==
const boundary = `(\\b|[-'".,;:‘’])`
function getAllTextNodes(parent){
var result = [];
(function scanSubTree(node){
if(node.childNodes.length)
for(var i = 0; i < node.childNodes.length; i++)
scanSubTree(node.childNodes[i]);
else if(node.nodeType == Node.TEXT_NODE)
result.push(node);
})(parent || document);
return result;
}
function quote(str){
return (str+'').replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
}
function replaceTextOnPage(from, to, parent){
const re = new RegExp(boundary + quote(from) + boundary, 'gi')
console.log(re)
getAllTextNodes(parent).forEach(function(node){
node.nodeValue = node.nodeValue.replace(re, `$1${to}$2`);
});
}
function replaceAi() {
replaceTextOnPage('ai', GM_getValue('replacer', 'slop'));
}
replaceAi()
const observer = new MutationObserver(list => {
list.forEach(node => replaceAi(node.target))
});
observer.observe(document.body, { childList: true, subtree: true });
GM_registerMenuCommand("AI replacer", () => {
GM_setValue('replacer', prompt("What should be shown instead of AI?", GM_getValue('replacer', 'slop')))
}, { autoClose:true});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment