forked from rchern/StackExchangeScripts
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSEChatFaviconNotification.user.js
More file actions
48 lines (39 loc) · 1.51 KB
/
Copy pathSEChatFaviconNotification.user.js
File metadata and controls
48 lines (39 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// ==UserScript==
// @name Stack Overflow Chat Favicon Notifier
// @namespace yijiang
// @description Watches the SO Chat for new messages, and changes the Favicon accordingly
// @include http://chat.stackoverflow.com/rooms/*
// @include http://chat.meta.stackoverflow.com/rooms/*
// ==/UserScript==
var title = document.title;
setInterval(function(){
if(title !== document.title){
title = document.title;
var times, mention = false, ctitle = title;
if(title.indexOf('(') === 0){
ctitle = title.substring(1, title.indexOf(')'));
if(ctitle.indexOf('*') > -1){
mention = true;
if(ctitle.length === 1){
times = 0;
} else {
times = parseInt(ctitle, 10);
}
} else {
times = parseInt(ctitle, 10);
}
} else {
times = 0;
}
var url = (times > 0) ? 'http://dl.dropbox.com/u/1722364/so-favicon/so-' + (times > 30 ? 31 : times) + (mention ? 'm' : '') + '.png' : 'http://sstatic.net/stackoverflow/img/favicon.ico';
var headElements = document.getElementsByTagName('head')[0].childNodes;
for(var i = 0; i < headElements.length; i++){
if(headElements[i].tagName === 'LINK' && headElements[i].getAttribute('rel').indexOf('shortcut') > -1){
var newLink = headElements[i].cloneNode(false);
newLink.href = url;
document.getElementsByTagName('head')[0].replaceChild(newLink, headElements[i]);
break;
}
}
}
}, 500);