Created
June 27, 2024 18:07
-
-
Save ylt6/3636baabde91b7a6a6651260254ef79f to your computer and use it in GitHub Desktop.
tampermonkey_text_replacement_script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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