Skip to content

Commit

Permalink
plugin/reply_favicon.js: Notify reply with favicon and title
Browse files Browse the repository at this point in the history
  • Loading branch information
Atsushi Takayama committed Sep 13, 2010
1 parent fc015e3 commit eb61af5
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Binary file added favicon_reply.ico
Binary file not shown.
61 changes: 61 additions & 0 deletions plugins/reply_favicon.js
@@ -0,0 +1,61 @@

(function() {
// http://stackoverflow.com/questions/260857/changing-website-favicon-dynamically
/*!
* Dynamically changing favicons with JavaScript
* Works in all A-grade browsers except Safari and Internet Explorer
* Demo: http://mathiasbynens.be/demo/dynamic-favicons
*/

// HTML5™, baby! http://mathiasbynens.be/notes/document-head
document.head = document.head || document.getElementsByTagName('head')[0];

// Browser sniffing :`(
if (/Chrome/.test(navigator.userAgent)) {
var isChrome = 1,
iframe = document.createElement('iframe');
iframe.src = 'about:blank';
iframe.style.display = 'none';
document.body.appendChild(iframe);
};

function changeFavicon(src) {
var link = document.createElement('link'),
oldLink = document.getElementById('dynamic-favicon');
link.id = 'dynamic-favicon';
link.rel = 'shortcut icon';
link.href = src;
if (oldLink) {
document.head.removeChild(oldLink);
};
document.head.appendChild(link);
if (isChrome) {
iframe.src += '';
};
};

// original code from here
var favicon_status = 'normal';
var title = document.title;

function toReplyFavicon () {
if (favicon_status === 'normal') {
changeFavicon('favicon_reply.ico');
favicon_status = 'reply';
document.title = '\u261c ' + title;
}
}

function toNormalFavicon (tab) {
if (tab.id !== 'reply') return;
changeFavicon('favicon.ico');
favicon_status = 'normal';
document.title = title;
}

registerPlugin({
noticeNewReply: toReplyFavicon,
switchTo: toNormalFavicon
});

})();

0 comments on commit eb61af5

Please sign in to comment.