Skip to content

Instantly share code, notes, and snippets.

@adambarreiro
Last active August 29, 2015 14:17
Show Gist options
  • Save adambarreiro/22847b6d0832cc8e3bb1 to your computer and use it in GitHub Desktop.
Save adambarreiro/22847b6d0832cc8e3bb1 to your computer and use it in GitHub Desktop.
Clickable Carlton Banks injection
/**
* This is an extension of this Gist: https://gist.github.com/miquelcamps/5b7561f9c564e93b7eee
* The original function attached a Carlton Banks dancing to Tom Jones' It's Not Unusual
* to your current browser page.
* This function, besides that, allows to attach a click event with an ON/OFF behaviour.
* A click will fire this dancing Carlton and another click will remove it.
*
* "target" can be an identifier, a class or the name attribute of the element to click.
* Simply put this string instead of "YOUR_DIV_HERE".
*/
(function(target) {
var carlton = null;
var switchCarlton = function() {
if (carlton) deleteCarlton();
else addCarlton();
return false;
};
var deleteCarlton = function() {
carlton.parentNode.removeChild(carlton);
carlton = null;
};
var addCarlton = function() {
carlton = document.createElement('div');
carlton.id = 'carltonbanks';
carlton.innerHTML = '<img src="http://i.imgur.com/YdmGHYG.gif" style="position:fixed;right:0;bottom:0;"><audio autoplay><source src="http://40mp3.com/music/user-files-30/0000/all-genre/074%20-%20Its%20Not%20Unusual%20-%20Tom%20Jones%20-%201391998460.mp3" type="audio/mpeg"></audio>';
document.body.appendChild(carlton);
};
var element = document.getElementById(target) || document.getElementsByClassName(target)[0] || document.getElementsByName(target)[0];
if (element !== null) {
element.addEventListener('click', switchCarlton);
}
})("YOUR_DIV_HERE");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment