Skip to content

Instantly share code, notes, and snippets.

@Ratismal
Last active July 16, 2020 23:46
Show Gist options
  • Save Ratismal/cac84c6a5242666bb5df732e1d34d486 to your computer and use it in GitHub Desktop.
Save Ratismal/cac84c6a5242666bb5df732e1d34d486 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Adam Sandler
// @namespace https://stupidcat.me/adam_sandler.user.js
// @version 0.1
// @updateURL https://stupidcat.me/adam_sandler.user.js
// @downloadURL https://stupidcat.me/adam_sandler.user.js
// @description adam sandler
// @author stupid cat
// @include *
// @grant none
// ==/UserScript==
(function() {
'use strict';
// modified from https://stackoverflow.com/a/50537862
function replaceInText(element, replacement) {
for (let node of element.childNodes) {
switch (node.nodeType) {
case Node.ELEMENT_NODE:
replaceInText(node, replacement);
break;
case Node.TEXT_NODE:
if (node.textContent.trim()) {
console.log('replacing', node.textContent);
node.textContent = node.textContent.replace(/^(\s*).+?(\s*)$/, `$1${replacement}$2`);
}
break;
case Node.DOCUMENT_NODE:
replaceInText(node, replacement);
}
}
}
replaceInText(document, 'Adam Sandler');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment