Skip to content

Instantly share code, notes, and snippets.

@ylt6
Created June 27, 2024 18:07
Show Gist options
  • Save ylt6/3636baabde91b7a6a6651260254ef79f to your computer and use it in GitHub Desktop.
Save ylt6/3636baabde91b7a6a6651260254ef79f to your computer and use it in GitHub Desktop.
tampermonkey_text_replacement_script
(function() {
var replaceArry = [
[/replaceme/gi, 'newtext'],
];
function replace_text() {
var numTerms = replaceArry.length;
var txtWalker = document.createTreeWalker(
document.body,
NodeFilter.SHOW_TEXT, {
acceptNode: function(node) {
if(node.nodeValue.trim())
return NodeFilter.FILTER_ACCEPT;
return NodeFilter.FILTER_SKIP;
}
},
false
);
var txtNode = null;
while(txtNode = txtWalker.nextNode()) {
var oldTxt = txtNode.nodeValue;
for(var J = 0; J < numTerms; J++) {
oldTxt = oldTxt.replace(replaceArry[J][0], replaceArry[J][1]);
}
txtNode.nodeValue = oldTxt;
}
}
setTimeout(replace_text, 1000);
setInterval(function() {
document.addEventListener("scroll", replace_text, true);
}, 100);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment