Last active
February 20, 2016 15:03
-
-
Save stewart/3ef4da827194221cab1e to your computer and use it in GitHub Desktop.
UserScript to correct "Donald Trump" to "Known buffoon, Donald Trump"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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