Created
September 30, 2021 19:53
-
-
Save RemyPorter/f9981625a01377cfe586dbab29335b35 to your computer and use it in GitHub Desktop.
Replace all references to NFTs with references to POGs on all websites
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
// ==UserScript== | |
// @name Poggers | |
// @desc Replace references to "NFTs" with references to "POGs" | |
// @grant none | |
// @match *://*/* | |
// @version 1.0 | |
// ==/UserScript== | |
var replaceArry = [ | |
[/\bNFT(s)?\b/gi, function(match, plural) { | |
return plural ? "POGs" : "POG" | |
}], | |
// etc. | |
]; | |
var numTerms = replaceArry.length; | |
var transTimer = setInterval (translateTermsOnPage, 500); | |
function translateTermsOnPage () { | |
/*--- Replace text on the page without busting links or javascript | |
functionality. | |
*/ | |
var txtWalker = document.createTreeWalker ( | |
document.body, | |
NodeFilter.SHOW_TEXT, { | |
acceptNode: function (node) { | |
//-- Skip whitespace-only nodes | |
if (node.nodeValue.trim() ) { | |
if (node.tmWasProcessed) | |
return NodeFilter.FILTER_SKIP; | |
else | |
return NodeFilter.FILTER_ACCEPT; | |
} | |
return NodeFilter.FILTER_SKIP; | |
} | |
}, | |
false | |
); | |
var txtNode = null; | |
while (txtNode = txtWalker.nextNode () ) { | |
txtNode.nodeValue = replaceAllTerms (txtNode.nodeValue); | |
txtNode.tmWasProcessed = true; | |
} | |
} | |
function replaceAllTerms (oldTxt) { | |
for (var J = 0; J < numTerms; J++) { | |
oldTxt = oldTxt.replaceAll(replaceArry[J][0], replaceArry[J][1]); | |
} | |
return oldTxt; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment