Skip to content

Instantly share code, notes, and snippets.

@sphvn
Created November 21, 2011 06:32
Show Gist options
  • Save sphvn/1381841 to your computer and use it in GitHub Desktop.
Save sphvn/1381841 to your computer and use it in GitHub Desktop.
Animooted Nyan Favicon
// *** First of all the Favicon.js, Favicon.js - [http://ajaxify.com/run/favicon] ***
var favicon = {
defaultPause: 500,
change: function(iconURL, optionalDocTitle) {
clearTimeout(this.loopTimer);
if (optionalDocTitle) {
document.title = optionalDocTitle;
}
this.addLink(iconURL, true);
},
animate: function(iconSequence, optionalDelay) {
this.preloadIcons(iconSequence);
this.iconSequence = iconSequence;
this.sequencePause = (optionalDelay) ? optionalDelay : this.defaultPause;
favicon.index = 0;
favicon.change(iconSequence[0]);
this.loopTimer = setInterval(function() {
favicon.index = (favicon.index+1) % favicon.iconSequence.length;
favicon.addLink(favicon.iconSequence[favicon.index], false);
}, favicon.sequencePause);
},
loopTimer: null,
preloadIcons: function(iconSequence) {
var dummyImageForPreloading = document.createElement("img");
for (var i=0; i<iconSequence.length; i++) {
dummyImageForPreloading.src = iconSequence[i];
}
},
addLink: function(iconURL) {
var link = document.createElement("link");
link.type = "image/x-icon";
link.rel = "shortcut icon";
link.href = iconURL;
this.removeLinkIfExists();
this.docHead.appendChild(link);
},
removeLinkIfExists: function() {
var links = this.docHead.getElementsByTagName("link");
for (var i=0; i<links.length; i++) {
var link = links[i];
if (link.type=="image/x-icon" && link.rel=="shortcut icon") {
this.docHead.removeChild(link);
return; // Assuming only one match at most.
}
}
},
docHead:document.getElementsByTagName("head")[0]
}
// *** Now the icons ***
favicon.animate(
new Array(
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAMAUExURQ8YIQwbLgQeNxMXMBMeMh0XOR4fMQ0gPhUiNRUnOyMcOyEpLCEvMCQ+PTgzMAIpSgYqTgcnUAAuWgUuXAorVAsuVAgvVg4rUw0qVwwtUAwvW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kimpmiWR0jW91gXtthGqlVWipWYdPfoxSeo1BgpFjipJ6iqB5mLhpqoO0Y52xabPge7ThfIuJlJKCjZqPlZGVmJyTmISKopaMpZKUoKeJobibr7jigM+QyduYwd6c48Sgxt2i0t2h4eWT3e6U1POY0++T6PGT5/SZ6fqc6vqf7v2f9+es2uqm1+O/y/Cyx+Gg5Omj6eit4+un8OW24uSx6fOt4QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJj3aiYAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My41LjVJivzgAAABG0lEQVQoUwEQAe/+AHF3IVtvcHJaJyNjZGVpUF4AYE92JGdnTi4rMhwzZhl8TwBifk8sRT84Nzs6Q0QVfRdZAF9HczQ9p6aio6OkpYwteCQAg29TQpfayNnF1tfbvgURKQBBHjU5nNPO0cmvs8exhkYgAAkLhwGb3M3Mw7CynqC/iS8AlJGSkJrEz9CtwLm8urioNgC2t8K1n9XLyq7BnbuhmL08AKyrtJMK1NLYxqqplZaZiD4Aj42OiosIAg0MAAYDBwRAHwBMhUsaMBITHRsxDg8QFIBWAIJKSHRnFoFrfBh5KGpfTlwAbnt6VmyESVdxTV9fcVVhXABYIlBVbVJ1bV13UVUXWWFiACUqVGBoSXVSUGFXVn8mTXr3Hmu6vgXxNAAAAABJRU5ErkJggg=="
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment