Skip to content

Instantly share code, notes, and snippets.

@juliocesar
Last active Aug 29, 2015
Embed
What would you like to do?
catalanifyme.js
// 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