Last active
December 27, 2015 18:48
-
-
Save jiaaro/7372006 to your computer and use it in GitHub Desktop.
v1 of implementing xkcd substituions: http://xkcd.com/1288/
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
function replace(txt) { | |
txt = txt.replace(/witnesses/gi, "dudes I know"); | |
txt = txt.replace(/allegedly/gi, "kinda probably"); | |
txt = txt.replace(/new study/gi, "tumblr post"); | |
txt = txt.replace(/rebuild/gi, "avenge"); | |
txt = txt.replace(/space/gi, "spaaace"); | |
txt = txt.replace(/google glass/gi, "virtual boy"); | |
txt = txt.replace(/smartphone/gi, "pokédex"); | |
txt = txt.replace(/electric/gi, "atomic"); | |
txt = txt.replace(/senator/gi, "elf-lord"); | |
txt = txt.replace(/car/gi, "cat"); | |
txt = txt.replace(/election/gi, "eating contest"); | |
txt = txt.replace(/congressional leaders/gi, "river spirits"); | |
txt = txt.replace(/homeland security/gi, "homestar runner"); | |
txt = txt.replace(/could not be reached for comment/gi, "is guilty and everyone knows it"); | |
return txt; | |
} | |
function replace_all_on_page() { | |
function recurse(element) | |
{ | |
if (element.childNodes.length > 0) | |
for (var i = 0; i < element.childNodes.length; i++) | |
recurse(element.childNodes[i]); | |
if (element.nodeType == Node.TEXT_NODE) { | |
window.el = element | |
element.textContent = replace(element.textContent); | |
} | |
} | |
var html = document.getElementsByTagName('html')[0]; | |
recurse(html); | |
} | |
replace_all_on_page(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Iterating through
document.all
might be better (benchmarking required)