public
Last active

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.

  • Download Gist
XKCD1288.user.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
// ==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));
});
 
})();

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.