Make Unread Favicon option, independant of Unread Favicon. Remove the 'None' favicon choice. Refactor.

Close #100
This commit is contained in:
Nicolas Stepien 2012-02-05 17:38:28 +01:00
parent c73d0e17f2
commit 5291ef5ac1
3 changed files with 80 additions and 84 deletions

View File

@ -105,6 +105,7 @@
Monitoring: { Monitoring: {
'Thread Updater': [true, 'Update threads. Has more options in its own dialog.'], 'Thread Updater': [true, 'Update threads. Has more options in its own dialog.'],
'Unread Count': [true, 'Show unread post count in tab title'], 'Unread Count': [true, 'Show unread post count in tab title'],
'Unread Favicon': [true, 'Show a different favicon when there are unread posts'],
'Post in Title': [true, 'Show the op\'s post in the tab title'], 'Post in Title': [true, 'Show the op\'s post in the tab title'],
'Thread Stats': [true, 'Display reply and image count'], 'Thread Stats': [true, 'Display reply and image count'],
'Thread Watcher': [true, 'Bookmark threads'], 'Thread Watcher': [true, 'Bookmark threads'],
@ -167,7 +168,7 @@
expandImages: ['m', 'Expand selected image'], expandImages: ['m', 'Expand selected image'],
expandAllImages: ['M', 'Expand all images'], expandAllImages: ['M', 'Expand all images'],
update: ['u', 'Update now'], update: ['u', 'Update now'],
unreadCountTo0: ['z', 'Reset unread count to 0'] unreadCountTo0: ['z', 'Reset unread status']
}, },
updater: { updater: {
checkbox: { checkbox: {
@ -971,8 +972,7 @@
break; break;
case conf.unreadCountTo0: case conf.unreadCountTo0:
unread.replies = []; unread.replies = [];
unread.updateTitle(); unread.update();
Favicon.update();
break; break;
default: default:
return; return;
@ -2025,14 +2025,13 @@
<li>Hour: %k, %H, %l (lowercase L), %I (uppercase i), %p, %P</li>\ <li>Hour: %k, %H, %l (lowercase L), %I (uppercase i), %p, %P</li>\
<li>Minutes: %M</li>\ <li>Minutes: %M</li>\
</ul>\ </ul>\
<div class=warning><code>Unread Count</code> is disabled.</div>\ <div class=warning><code>Unread Favicon</code> is disabled.</div>\
Unread favicons<br>\ Unread favicons<br>\
<select name=favicon>\ <select name=favicon>\
<option value=ferongr>ferongr</option>\ <option value=ferongr>ferongr</option>\
<option value=xat->xat-</option>\ <option value=xat->xat-</option>\
<option value=Mayhem>Mayhem</option>\ <option value=Mayhem>Mayhem</option>\
<option value=Original>Original</option>\ <option value=Original>Original</option>\
<option value=None>None</option>\
</select>\ </select>\
<span></span>\ <span></span>\
</div>\ </div>\
@ -2150,7 +2149,7 @@
}, },
favicon: function() { favicon: function() {
Favicon["switch"](); Favicon["switch"]();
if (g.REPLY && conf['Unread Count']) Favicon.update(); unread.update(true);
return this.nextElementSibling.innerHTML = "<img src=" + Favicon.unreadSFW + "> <img src=" + Favicon.unreadNSFW + "> <img src=" + Favicon.unreadDead + ">"; return this.nextElementSibling.innerHTML = "<img src=" + Favicon.unreadSFW + "> <img src=" + Favicon.unreadNSFW + "> <img src=" + Favicon.unreadDead + ">";
} }
}; };
@ -2366,8 +2365,13 @@
updater.count.textContent = 404; updater.count.textContent = 404;
updater.count.className = 'warning'; updater.count.className = 'warning';
clearTimeout(updater.timeoutID); clearTimeout(updater.timeoutID);
d.title = d.title.match(/^.+-/)[0] + ' 404';
g.dead = true; g.dead = true;
if (conf['Unread Count']) {
unread.title = unread.title.match(/^.+-/)[0] + ' 404';
} else {
d.title = d.title.match(/^.+-/)[0] + ' 404';
}
unread.update(true);
qr.message.send({ qr.message.send({
req: 'abort' req: 'abort'
}); });
@ -2831,10 +2835,9 @@
root = q.parentNode.nodeName === 'FONT' ? q.parentNode : q.nextSibling ? q.nextSibling : q; root = q.parentNode.nodeName === 'FONT' ? q.parentNode : q.nextSibling ? q.nextSibling : q;
if (el = $.id(id)) { if (el = $.id(id)) {
inline = quoteInline.table(id, el.innerHTML); inline = quoteInline.table(id, el.innerHTML);
if (g.REPLY && conf['Unread Count'] && (i = unread.replies.indexOf(el.parentNode.parentNode.parentNode)) !== -1) { if ((i = unread.replies.indexOf(el.parentNode.parentNode.parentNode)) !== -1) {
unread.replies.splice(i, 1); unread.replies.splice(i, 1);
unread.updateTitle(); unread.update();
Favicon.update();
} }
if (/\bbacklink\b/.test(q.className)) { if (/\bbacklink\b/.test(q.className)) {
$.after(q.parentNode, inline); $.after(q.parentNode, inline);
@ -3104,7 +3107,8 @@
unread = { unread = {
init: function() { init: function() {
d.title = '(0) ' + d.title; this.title = d.title;
unread.update();
$.on(window, 'scroll', unread.scroll); $.on(window, 'scroll', unread.scroll);
return g.callbacks.push(unread.node); return g.callbacks.push(unread.node);
}, },
@ -3112,8 +3116,7 @@
node: function(root) { node: function(root) {
if (root.hidden || root.className) return; if (root.hidden || root.className) return;
unread.replies.push(root); unread.replies.push(root);
unread.updateTitle(); return unread.update();
if (unread.replies.length === 1) return Favicon.update();
}, },
scroll: function() { scroll: function() {
var bottom, height, i, reply, _len, _ref; var bottom, height, i, reply, _len, _ref;
@ -3126,20 +3129,25 @@
} }
if (i === 0) return; if (i === 0) return;
unread.replies = unread.replies.slice(i); unread.replies = unread.replies.slice(i);
unread.updateTitle(); return unread.update();
if (unread.replies.length === 0) return Favicon.update();
}, },
updateTitle: function() { update: function(forceUpdate) {
return d.title = d.title.replace(/\d+/, unread.replies.length); var count;
if (!g.REPLY) return;
count = unread.replies.length;
if (conf['Unread Count']) d.title = "(" + count + ") " + unread.title;
if (!(conf['Unread Favicon'] && count < 2 || forceUpdate)) return;
Favicon.el.href = g.dead ? count ? Favicon.unreadDead : Favicon.dead : count ? Favicon.unread : Favicon["default"];
if (engine !== 'webkit') return $.add(d.head, $.rm(Favicon.el));
} }
}; };
Favicon = { Favicon = {
init: function() { init: function() {
var favicon, href; var href;
favicon = $('link[rel="shortcut icon"]', d.head); this.el = $('link[rel="shortcut icon"]', d.head);
favicon.type = 'image/x-icon'; this.el.type = 'image/x-icon';
href = favicon.href; href = this.el.href;
this.SFW = /ws.ico$/.test(href); this.SFW = /ws.ico$/.test(href);
this["default"] = href; this["default"] = href;
return this["switch"](); return this["switch"]();
@ -3165,23 +3173,11 @@
this.unreadDead = 'data:unreadDead;base64,R0lGODlhEAAQAKECAAAAAP8AAP///////yH5BAEKAAMALAAAAAAQABAAAAI/nI95wsqygIRxDgGCBhTrwF3Zxowg5H1cSopS6FrGQ82PU1951ckRmYKJVCXizLRC9kAnT0aIiR6lCFT1cigAADs='; this.unreadDead = 'data:unreadDead;base64,R0lGODlhEAAQAKECAAAAAP8AAP///////yH5BAEKAAMALAAAAAAQABAAAAI/nI95wsqygIRxDgGCBhTrwF3Zxowg5H1cSopS6FrGQ82PU1951ckRmYKJVCXizLRC9kAnT0aIiR6lCFT1cigAADs=';
this.unreadSFW = 'data:unreadSFW;base64,R0lGODlhEAAQAKECAAAAAC6Xw////////yH5BAEKAAMALAAAAAAQABAAAAI/nI95wsqygIRxDgGCBhTrwF3Zxowg5H1cSopS6FrGQ82PU1951ckRmYKJVCXizLRC9kAnT0aIiR6lCFT1cigAADs='; this.unreadSFW = 'data:unreadSFW;base64,R0lGODlhEAAQAKECAAAAAC6Xw////////yH5BAEKAAMALAAAAAAQABAAAAI/nI95wsqygIRxDgGCBhTrwF3Zxowg5H1cSopS6FrGQ82PU1951ckRmYKJVCXizLRC9kAnT0aIiR6lCFT1cigAADs=';
this.unreadNSFW = 'data:unreadNSFW;base64,R0lGODlhEAAQAKECAAAAAGbMM////////yH5BAEKAAMALAAAAAAQABAAAAI/nI95wsqygIRxDgGCBhTrwF3Zxowg5H1cSopS6FrGQ82PU1951ckRmYKJVCXizLRC9kAnT0aIiR6lCFT1cigAADs='; this.unreadNSFW = 'data:unreadNSFW;base64,R0lGODlhEAAQAKECAAAAAGbMM////////yH5BAEKAAMALAAAAAAQABAAAAI/nI95wsqygIRxDgGCBhTrwF3Zxowg5H1cSopS6FrGQ82PU1951ckRmYKJVCXizLRC9kAnT0aIiR6lCFT1cigAADs=';
break;
case 'None':
this.unreadDead = this.dead;
this.unreadSFW = 'http://static.4chan.org/image/favicon-ws.ico';
this.unreadNSFW = 'http://static.4chan.org/image/favicon.ico';
} }
return this.unread = this.SFW ? this.unreadSFW : this.unreadNSFW; return this.unread = this.SFW ? this.unreadSFW : this.unreadNSFW;
}, },
empty: 'data:image/gif;base64,R0lGODlhEAAQAJEAAAAAAP///9vb2////yH5BAEAAAMALAAAAAAQABAAAAIvnI+pq+D9DBAUoFkPFnbs7lFZKIJOJJ3MyraoB14jFpOcVMpzrnF3OKlZYsMWowAAOw==', empty: 'data:image/gif;base64,R0lGODlhEAAQAJEAAAAAAP///9vb2////yH5BAEAAAMALAAAAAAQABAAAAIvnI+pq+D9DBAUoFkPFnbs7lFZKIJOJJ3MyraoB14jFpOcVMpzrnF3OKlZYsMWowAAOw==',
dead: 'data:image/gif;base64,R0lGODlhEAAQAKECAAAAAP8AAP///////yH5BAEKAAIALAAAAAAQABAAAAIvlI+pq+D9DAgUoFkPDlbs7lFZKIJOJJ3MyraoB14jFpOcVMpzrnF3OKlZYsMWowAAOw==', dead: 'data:image/gif;base64,R0lGODlhEAAQAKECAAAAAP8AAP///////yH5BAEKAAIALAAAAAAQABAAAAIvlI+pq+D9DAgUoFkPDlbs7lFZKIJOJJ3MyraoB14jFpOcVMpzrnF3OKlZYsMWowAAOw=='
update: function() {
var favicon, l;
l = unread.replies.length;
favicon = $('link[rel="shortcut icon"]', d.head);
favicon.href = g.dead ? l ? this.unreadDead : this.dead : l ? this.unread : this["default"];
if (engine !== 'webkit') return $.add(d.head, $.rm(favicon));
}
}; };
redirect = { redirect = {
@ -3519,7 +3515,7 @@
if (conf['Thread Stats']) threadStats.init(); if (conf['Thread Stats']) threadStats.init();
if (conf['Reply Navigation']) nav.init(); if (conf['Reply Navigation']) nav.init();
if (conf['Post in Title']) titlePost.init(); if (conf['Post in Title']) titlePost.init();
if (conf['Unread Count']) unread.init(); if (conf['Unread Count'] || conf['Unread Favicon']) unread.init();
} else { } else {
if (conf['Thread Hiding']) threadHiding.init(); if (conf['Thread Hiding']) threadHiding.init();
if (conf['Thread Expansion']) expandThread.init(); if (conf['Thread Expansion']) expandThread.init();

View File

@ -4,6 +4,7 @@ master
- Mayhem - Mayhem
Increase Sauce linking possibilites: Increase Sauce linking possibilites:
Thumbnails, full images, MD5 hashes. Thumbnails, full images, MD5 hashes.
Unread Favicon is now optional, independent of Unread Count.
2.25.5 2.25.5
- Mayhem - Mayhem

View File

@ -26,6 +26,7 @@ config =
Monitoring: Monitoring:
'Thread Updater': [true, 'Update threads. Has more options in its own dialog.'] 'Thread Updater': [true, 'Update threads. Has more options in its own dialog.']
'Unread Count': [true, 'Show unread post count in tab title'] 'Unread Count': [true, 'Show unread post count in tab title']
'Unread Favicon': [true, 'Show a different favicon when there are unread posts']
'Post in Title': [true, 'Show the op\'s post in the tab title'] 'Post in Title': [true, 'Show the op\'s post in the tab title']
'Thread Stats': [true, 'Display reply and image count'] 'Thread Stats': [true, 'Display reply and image count']
'Thread Watcher': [true, 'Bookmark threads'] 'Thread Watcher': [true, 'Bookmark threads']
@ -96,7 +97,7 @@ config =
expandImages: ['m', 'Expand selected image'] expandImages: ['m', 'Expand selected image']
expandAllImages: ['M', 'Expand all images'] expandAllImages: ['M', 'Expand all images']
update: ['u', 'Update now'] update: ['u', 'Update now']
unreadCountTo0: ['z', 'Reset unread count to 0'] unreadCountTo0: ['z', 'Reset unread status']
updater: updater:
checkbox: checkbox:
'Scrolling': [false, 'Scroll updated posts into view. Only enabled at bottom of page.'] 'Scrolling': [false, 'Scroll updated posts into view. Only enabled at bottom of page.']
@ -713,8 +714,7 @@ keybinds =
qr.submit() if qr.el and !qr.status() qr.submit() if qr.el and !qr.status()
when conf.unreadCountTo0 when conf.unreadCountTo0
unread.replies = [] unread.replies = []
unread.updateTitle() unread.update()
Favicon.update()
else else
return return
e.preventDefault() e.preventDefault()
@ -1570,14 +1570,13 @@ options =
<li>Hour: %k, %H, %l (lowercase L), %I (uppercase i), %p, %P</li> <li>Hour: %k, %H, %l (lowercase L), %I (uppercase i), %p, %P</li>
<li>Minutes: %M</li> <li>Minutes: %M</li>
</ul> </ul>
<div class=warning><code>Unread Count</code> is disabled.</div> <div class=warning><code>Unread Favicon</code> is disabled.</div>
Unread favicons<br> Unread favicons<br>
<select name=favicon> <select name=favicon>
<option value=ferongr>ferongr</option> <option value=ferongr>ferongr</option>
<option value=xat->xat-</option> <option value=xat->xat-</option>
<option value=Mayhem>Mayhem</option> <option value=Mayhem>Mayhem</option>
<option value=Original>Original</option> <option value=Original>Original</option>
<option value=None>None</option>
</select> </select>
<span></span> <span></span>
</div> </div>
@ -1681,7 +1680,7 @@ options =
$.id('backlinkPreview').textContent = conf['backlink'].replace /%id/, '123456789' $.id('backlinkPreview').textContent = conf['backlink'].replace /%id/, '123456789'
favicon: -> favicon: ->
Favicon.switch() Favicon.switch()
Favicon.update() if g.REPLY and conf['Unread Count'] unread.update true
@nextElementSibling.innerHTML = "<img src=#{Favicon.unreadSFW}> <img src=#{Favicon.unreadNSFW}> <img src=#{Favicon.unreadDead}>" @nextElementSibling.innerHTML = "<img src=#{Favicon.unreadSFW}> <img src=#{Favicon.unreadNSFW}> <img src=#{Favicon.unreadDead}>"
threading = threading =
@ -1865,8 +1864,12 @@ updater =
updater.count.textContent = 404 updater.count.textContent = 404
updater.count.className = 'warning' updater.count.className = 'warning'
clearTimeout updater.timeoutID clearTimeout updater.timeoutID
d.title = d.title.match(/^.+-/)[0] + ' 404'
g.dead = true g.dead = true
if conf['Unread Count']
unread.title = unread.title.match(/^.+-/)[0] + ' 404'
else
d.title = d.title.match(/^.+-/)[0] + ' 404'
unread.update true
qr.message.send req: 'abort' qr.message.send req: 'abort'
qr.status() qr.status()
Favicon.update() Favicon.update()
@ -2217,10 +2220,9 @@ quoteInline =
root = if q.parentNode.nodeName is 'FONT' then q.parentNode else if q.nextSibling then q.nextSibling else q root = if q.parentNode.nodeName is 'FONT' then q.parentNode else if q.nextSibling then q.nextSibling else q
if el = $.id id if el = $.id id
inline = quoteInline.table id, el.innerHTML inline = quoteInline.table id, el.innerHTML
if g.REPLY and conf['Unread Count'] and (i = unread.replies.indexOf el.parentNode.parentNode.parentNode) isnt -1 if (i = unread.replies.indexOf el.parentNode.parentNode.parentNode) isnt -1
unread.replies.splice i, 1 unread.replies.splice i, 1
unread.updateTitle() unread.update()
Favicon.update()
if /\bbacklink\b/.test q.className if /\bbacklink\b/.test q.className
$.after q.parentNode, inline $.after q.parentNode, inline
$.addClass $.x('ancestor::table', el), 'forwarded' if conf['Forward Hiding'] $.addClass $.x('ancestor::table', el), 'forwarded' if conf['Forward Hiding']
@ -2392,7 +2394,8 @@ threadStats =
unread = unread =
init: -> init: ->
d.title = '(0) ' + d.title @title = d.title
unread.update()
$.on window, 'scroll', unread.scroll $.on window, 'scroll', unread.scroll
g.callbacks.push unread.node g.callbacks.push unread.node
@ -2401,9 +2404,7 @@ unread =
node: (root) -> node: (root) ->
return if root.hidden or root.className return if root.hidden or root.className
unread.replies.push root unread.replies.push root
unread.updateTitle() unread.update()
if unread.replies.length is 1
Favicon.update()
scroll: -> scroll: ->
height = d.body.clientHeight height = d.body.clientHeight
@ -2414,18 +2415,42 @@ unread =
return if i is 0 return if i is 0
unread.replies = unread.replies[i..] unread.replies = unread.replies[i..]
unread.updateTitle() unread.update()
if unread.replies.length is 0
Favicon.update()
updateTitle: -> update: (forceUpdate) ->
d.title = d.title.replace /\d+/, unread.replies.length return unless g.REPLY
count = unread.replies.length
if conf['Unread Count']
d.title = "(#{count}) #{unread.title}"
unless conf['Unread Favicon'] and count < 2 or forceUpdate
return
Favicon.el.href =
if g.dead
if count
Favicon.unreadDead
else
Favicon.dead
else
if count
Favicon.unread
else
Favicon.default
#`favicon.href = href` doesn't work on Firefox
#`favicon.href = href` isn't enough on Opera
#Opera won't always update the favicon if the href didn't not change
if engine isnt 'webkit'
$.add d.head, $.rm Favicon.el
Favicon = Favicon =
init: -> init: ->
favicon = $ 'link[rel="shortcut icon"]', d.head @el = $ 'link[rel="shortcut icon"]', d.head
favicon.type = 'image/x-icon' @el.type = 'image/x-icon'
{href} = favicon {href} = @el
@SFW = /ws.ico$/.test href @SFW = /ws.ico$/.test href
@default = href @default = href
@switch() @switch()
@ -2448,37 +2473,11 @@ Favicon =
@unreadDead = 'data:unreadDead;base64,R0lGODlhEAAQAKECAAAAAP8AAP///////yH5BAEKAAMALAAAAAAQABAAAAI/nI95wsqygIRxDgGCBhTrwF3Zxowg5H1cSopS6FrGQ82PU1951ckRmYKJVCXizLRC9kAnT0aIiR6lCFT1cigAADs=' @unreadDead = 'data:unreadDead;base64,R0lGODlhEAAQAKECAAAAAP8AAP///////yH5BAEKAAMALAAAAAAQABAAAAI/nI95wsqygIRxDgGCBhTrwF3Zxowg5H1cSopS6FrGQ82PU1951ckRmYKJVCXizLRC9kAnT0aIiR6lCFT1cigAADs='
@unreadSFW = 'data:unreadSFW;base64,R0lGODlhEAAQAKECAAAAAC6Xw////////yH5BAEKAAMALAAAAAAQABAAAAI/nI95wsqygIRxDgGCBhTrwF3Zxowg5H1cSopS6FrGQ82PU1951ckRmYKJVCXizLRC9kAnT0aIiR6lCFT1cigAADs=' @unreadSFW = 'data:unreadSFW;base64,R0lGODlhEAAQAKECAAAAAC6Xw////////yH5BAEKAAMALAAAAAAQABAAAAI/nI95wsqygIRxDgGCBhTrwF3Zxowg5H1cSopS6FrGQ82PU1951ckRmYKJVCXizLRC9kAnT0aIiR6lCFT1cigAADs='
@unreadNSFW = 'data:unreadNSFW;base64,R0lGODlhEAAQAKECAAAAAGbMM////////yH5BAEKAAMALAAAAAAQABAAAAI/nI95wsqygIRxDgGCBhTrwF3Zxowg5H1cSopS6FrGQ82PU1951ckRmYKJVCXizLRC9kAnT0aIiR6lCFT1cigAADs=' @unreadNSFW = 'data:unreadNSFW;base64,R0lGODlhEAAQAKECAAAAAGbMM////////yH5BAEKAAMALAAAAAAQABAAAAI/nI95wsqygIRxDgGCBhTrwF3Zxowg5H1cSopS6FrGQ82PU1951ckRmYKJVCXizLRC9kAnT0aIiR6lCFT1cigAADs='
when 'None'
@unreadDead = @dead
@unreadSFW = 'http://static.4chan.org/image/favicon-ws.ico'
@unreadNSFW = 'http://static.4chan.org/image/favicon.ico'
@unread = if @SFW then @unreadSFW else @unreadNSFW @unread = if @SFW then @unreadSFW else @unreadNSFW
empty: 'data:image/gif;base64,R0lGODlhEAAQAJEAAAAAAP///9vb2////yH5BAEAAAMALAAAAAAQABAAAAIvnI+pq+D9DBAUoFkPFnbs7lFZKIJOJJ3MyraoB14jFpOcVMpzrnF3OKlZYsMWowAAOw==' empty: 'data:image/gif;base64,R0lGODlhEAAQAJEAAAAAAP///9vb2////yH5BAEAAAMALAAAAAAQABAAAAIvnI+pq+D9DBAUoFkPFnbs7lFZKIJOJJ3MyraoB14jFpOcVMpzrnF3OKlZYsMWowAAOw=='
dead: 'data:image/gif;base64,R0lGODlhEAAQAKECAAAAAP8AAP///////yH5BAEKAAIALAAAAAAQABAAAAIvlI+pq+D9DAgUoFkPDlbs7lFZKIJOJJ3MyraoB14jFpOcVMpzrnF3OKlZYsMWowAAOw==' dead: 'data:image/gif;base64,R0lGODlhEAAQAKECAAAAAP8AAP///////yH5BAEKAAIALAAAAAAQABAAAAIvlI+pq+D9DAgUoFkPDlbs7lFZKIJOJJ3MyraoB14jFpOcVMpzrnF3OKlZYsMWowAAOw=='
update: ->
l = unread.replies.length
favicon = $ 'link[rel="shortcut icon"]', d.head
favicon.href =
if g.dead
if l
@unreadDead
else
@dead
else
if l
@unread
else
@default
#`favicon.href = href` doesn't work on Firefox
#`favicon.href = href` isn't enough on Opera
#Opera won't always update the favicon if the href do not change
if engine isnt 'webkit'
$.add d.head, $.rm favicon
redirect = redirect =
init: -> init: ->
url = url =
@ -2774,7 +2773,7 @@ Main =
if conf['Post in Title'] if conf['Post in Title']
titlePost.init() titlePost.init()
if conf['Unread Count'] if conf['Unread Count'] or conf['Unread Favicon']
unread.init() unread.init()
else #not reply else #not reply