Skip to content

Instantly share code, notes, and snippets.

Created November 9, 2013 18:02
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 anonymous/7388059 to your computer and use it in GitHub Desktop.
Save anonymous/7388059 to your computer and use it in GitHub Desktop.
{
"name": "XKCD Text",
"version": "0.1",
"permissions": [
"http://*/*"
],
"content_scripts": [
{
"matches": ["http://*/*"],
"js": ["xkcdfy.js"],
"run_at": "document_end"
}
],
"manifest_version": 2
}
String.prototype.replaceWithCase=function(subStr, newStr) {
return this.replace( new RegExp(subStr, 'ig'), function(found) {
return /[A-Z]/.test(found.charAt(0))?( newStr.charAt(0).toUpperCase() + newStr.substring(1) ) : newStr.toLowerCase();
});
}
var replacements = [["witnesses", "these dudes I know"],
["allegedly", "kinda probably"],
["new study", "tumbler post"],
["rebuild", "avenge"],
["space", "spaaace"],
["google glass", "virtual boy"],
["smartphone", "pokedex"],
["electric", "atomic"],
["senator", "elf-lord"],
["car", "cat"],
["election", "eating contest"],
["congressional leaders", "river spirits"],
["homeland security", "homestar runner"],
["could not be reached for comment", "is guilty and everyone knows it"]];
function replaceAll (text) {
var result = text;
for (r in replacements) {
var pair = replacements[r];
result = result.replaceWithCase(pair[0], pair[1]);
}
return result;
}
document.body.innerHTML = replaceAll(document.body.innerHTML);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment