Skip to content

Instantly share code, notes, and snippets.

@fdebijl
Created May 4, 2020 09:12
Show Gist options
  • Save fdebijl/f1d281d5d365e21d98aa354c5f9fc288 to your computer and use it in GitHub Desktop.
Save fdebijl/f1d281d5d365e21d98aa354c5f9fc288 to your computer and use it in GitHub Desktop.
sommige_millennials.js
// ==UserScript==
// @name Sommige millennials
// @version 1.0
// @description https://twitter.com/Schellevis/status/1257234072037986305
// @author Fdebijl
// @match *://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
walk(document.body);
function walk(node) {
let child, next;
switch (node.nodeType) {
case 1: // Element
case 9: // Document
case 11: // Document fragment
child = node.firstChild;
while (child) {
next = child.nextSibling;
walk(child);
child = next;
}
break;
case 3: // Text node
if (node.parentElement.tagName.toLowerCase() != "script") {
handleText(node);
}
break;
}
}
function handleText(textNode) {
let v = textNode.nodeValue;
if (v.match(/twintigers en dertigers/gi)) {
v = v.replace(/twintigers en dertigers/gi, function (match, p1, offset, string) {
return "sommige twintigers en dertigers";
});
} else if (v.match(/millennials/gi)) {
v = v.replace(/millennials/gi, function (match, p1, offset, string) {
return "sommige millennials";
});
}
textNode.nodeValue = v;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment