Skip to content

Instantly share code, notes, and snippets.

@RangerMauve
Last active December 27, 2015 19:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RangerMauve/7380912 to your computer and use it in GitHub Desktop.
Save RangerMauve/7380912 to your computer and use it in GitHub Desktop.
This is a filter I made that makes reading news more fun, I got the idea from http://xkcd.com/1288/. Since it's a userscript it should be easily install-able in Chrome or Firefox. In chrome it's as simple as downloading this file and dragging it into your "extensions" window.
// ==UserScript==
// @name FunNewsSubstitutions
// @namespace http://mauve.us.to
// @description This is a filter I made that makes reading news more fun, I got the idea from http://xkcd.com/1288/. Since it's a userscript it should be easily install-able in Chrome or Firefox
// @include *
// ==/UserScript==
// Wrapper to keep things in their own scope
(function(){
// Generate the replacement map
var f = {
"these dudes I know":/witnesses/mig,
"kinda probably":/allegedly/mig,
"Tumblr post":/new study/mig,
"Avenge":/rebuild/mig,
"SPAAACE":/space/mig,
"Virtual Boy":/google glass/mig,
"Pokédex":/smart\s?phone/mig,
"atomic":/electric/mig,
"Elf-Lord":/senator/mig,
"cat":/car/mig,
"eating contest":/election/mig,
"river spirits":/congressional leaders/mig,
"Homestar Runner":/homeland security/mig,
"is guilty and everyone knows it":/could not be reached for comment/mig
}
// Gets all the text nodes from a given DOM node
function getTextNodes(from){
var n, a=[], w=document.createTreeWalker(from,NodeFilter.SHOW_TEXT,null,false);
while(n=w.nextNode())a.push(n);
return a;
}
// Processes an array of TextNodes and performs substitution on the text they contain
function substitute(a){
a.forEach(function(e){
var key;
for(key in f)e.nodeValue=e.nodeValue.replace(f[key],key);
});
}
// Do the substitution on everything at page load
substitute(getTextNodes(document.body));
// Perform the substitution whenever a new node is added to support AJAX sites
document.body.addEventListener("DOMNodeInserted",function(e){
substitute(getTextNodes(e.target));
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment