Skip to content

Instantly share code, notes, and snippets.

@stewart
Last active February 20, 2016 15:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stewart/3ef4da827194221cab1e to your computer and use it in GitHub Desktop.
Save stewart/3ef4da827194221cab1e to your computer and use it in GitHub Desktop.
UserScript to correct "Donald Trump" to "Known buffoon, Donald Trump"
// ==UserScript==
// @name Known Buffoon, Known buffoon, Donald Trump
// @namespace https://gist.github.com/stewart
// @description Prefixes any occurence of "Donald Trump" with "Known buffoon, "
// @version 2015.08.09
// @author stewart
// @run-at document-end
// @include http*
// ==/UserScript==
(function() {
"use strict";
// credit to @gabrielg for the idea - https://twitter.com/gabrielgironda/status/630536698095661056
function transform(node) {
var value = node.nodeValue;
value = value.replace(/\bDonald (John )?Trump\b/i, "Known buffoon, $&");
node.nodeValue = value;
}
// from http://is.gd/mwZp7E
// via https://github.com/panicsteve/cloud-to-butt
function walk(node) {
var child, next;
switch (node.nodeType) {
case 1:
case 9:
case 11: // element, document, document fragment
child = node.firstChild;
while (child) {
next = child.nextSibling;
walk(child);
child = next;
}
break;
case 3: // text node
transform(node);
break;
}
}
walk(document.body);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment