Skip to content

Instantly share code, notes, and snippets.

@juliocesar
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliocesar/6d5dbd36c013c9a351a5 to your computer and use it in GitHub Desktop.
Save juliocesar/6d5dbd36c013c9a351a5 to your computer and use it in GitHub Desktop.
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