Skip to content

Instantly share code, notes, and snippets.

@RemyPorter
Created September 30, 2021 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RemyPorter/f9981625a01377cfe586dbab29335b35 to your computer and use it in GitHub Desktop.
Save RemyPorter/f9981625a01377cfe586dbab29335b35 to your computer and use it in GitHub Desktop.
Replace all references to NFTs with references to POGs on all websites
// ==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