Skip to content

Instantly share code, notes, and snippets.

@SteveHere
Created December 3, 2021 08:56
Show Gist options
  • Save SteveHere/32cfbe95f601ce6e3c08c0153f1188d5 to your computer and use it in GitHub Desktop.
Save SteveHere/32cfbe95f601ce6e3c08c0153f1188d5 to your computer and use it in GitHub Desktop.
"The economy" -> "Rich people's yacht money" word replacer
// ==UserScript==
// @name "The economy" to "Rich people's yacht money"
// @version 0.1
// @author SteveHere
// @match https://*.reddit.com/*
// @grant none
// ==/UserScript==
// Brought up by: https://twitter.com/onyxaminedlife/status/1334578466851852290
// This is a simple Tampermonkey script in response.
// This should work almost anywhere, as it just looks for text.
(function() { 'use strict';
function walk(node) { // I stole this function from here: http://is.gd/mwZp7E
let counter = 0;
let tagName = node.tagName ? node.tagName.toLowerCase() : "";
if (tagName == 'input' || tagName == 'textarea' || (node.classList && node.classList.contains('ace_editor'))) return 0;
switch ( node.nodeType ) {
case 1: case 9: case 11: { // Element, Document, Document fragment
let child = node.firstChild;
while(child){ counter += walk(child); child = child.nextSibling; }
} break;
case 3: // Text node
node.nodeValue = (v=>{
if(v.includes("The economy")){ v = v.replace(/\bThe Economy\b/g, "Rich people's yacht money"); counter++; }
if(v.includes("the economy")){ v = v.replace(/\bthe economy\b/g, "rich people's yacht money"); counter++; }
return v;
})(node.nodeValue); break;
}
return counter;
}
// TODO: change this to only trigger on DOM change
window.te_to_rpym = setInterval(()=>{
console.log(document.URL + ": Replaced " + walk(document.body); + " instances.");
}, 1000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment