Last active
August 29, 2015 14:08
-
-
Save juliocesar/6d5dbd36c013c9a351a5 to your computer and use it in GitHub Desktop.
catalanifyme.js
This file contains hidden or 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
// Catalanify-me dot jay ass | |
// ========================= | |
// | |
// Replaces all copy in your website with that famous sentence from an Adam | |
// Sandler film, "I'm here for the beer and the britches" (or was it something | |
// else? I can't remember…) said in Catalanese. | |
// | |
// Instalation: | |
// | |
// At some point in the page, load this script and run: | |
// | |
// Cat.run() | |
// | |
// Likely as this: | |
// | |
// window.addEventListener('load', function() { | |
// Cat.run(); | |
// }, false); | |
// | |
// NOTE: it'll make it look horrible. But if websites needed to be pretty in | |
// order to be up, we'd be nearly all out of websites. | |
(function(d) { | |
var copy = "Aquí per la cervesa i els pantalons"; | |
var willRun = navigator.language == 'ca'; | |
var rootNode = document.body; | |
// Shameless StackOverflow copying: | |
// http://stackoverflow.com/questions/10730309/find-all-text-nodes-in-html-page | |
var textNodesUnderNode = function (node){ | |
var collected = []; | |
for (node = node.firstChild; node; node = node.nextSibling) { | |
node.nodeType == 3 ? | |
collected.push(node) : | |
collected = collected.concat(textNodesUnderNode(node)); | |
} | |
return collected; | |
} | |
var Cat = { | |
run: function(force) { | |
if (willRun === false && force !== true) return false; | |
nodes = textNodesUnderNode(rootNode) | |
nodes.forEach(function(node) { | |
node.textContent = copy; | |
}) | |
}, | |
}; | |
if (typeof module !== 'undefined') { | |
module.exports = Cat; | |
} else { | |
window.Cat = Cat; | |
} | |
})(document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment