The Thread Updater now updates the sticky/closed icons.

It will also open notifications when these change. Close #934.
This commit is contained in:
Nicolas Stepien 2013-02-23 00:49:44 +01:00
parent 02fc7fecb3
commit 9725a26807
3 changed files with 58 additions and 0 deletions

View File

@ -5316,9 +5316,37 @@
} }
}); });
}, },
updateThreadStatus: function(title, OP) {
var icon, message, root, titleLC;
titleLC = title.toLowerCase();
if (ThreadUpdater.thread["is" + title] === !!OP[titleLC]) {
return;
}
if (!(ThreadUpdater.thread["is" + title] = !!OP[titleLC])) {
message = title === 'Sticky' ? 'The thread is not a sticky anymore.' : 'The thread is not closed anymore.';
new Notification('info', message, 30);
$.rm($("." + titleLC + "Icon", ThreadUpdater.thread.OP.nodes.info));
return;
}
message = title === 'Sticky' ? 'The thread is now a sticky.' : 'The thread is now closed.';
new Notification('info', message, 30);
icon = $.el('img', {
src: "//static.4chan.org/image/" + titleLC + ".gif",
alt: title,
title: title,
className: "" + titleLC + "Icon"
});
root = $('[title="Quote this post"]', ThreadUpdater.thread.OP.nodes.info);
if (title === 'Closed') {
root = $('.stickyIcon', ThreadUpdater.thread.OP.nodes.info) || root;
}
return $.after(root, [$.tn(' '), icon]);
},
parse: function(postObjects) { parse: function(postObjects) {
var ID, count, deletedFiles, deletedPosts, files, index, node, nodes, num, post, postObject, posts, scroll, _i, _len, _ref; var ID, count, deletedFiles, deletedPosts, files, index, node, nodes, num, post, postObject, posts, scroll, _i, _len, _ref;
Build.spoilerRange[ThreadUpdater.thread.board] = postObjects[0].custom_spoiler; Build.spoilerRange[ThreadUpdater.thread.board] = postObjects[0].custom_spoiler;
ThreadUpdater.updateThreadStatus('Sticky', postObjects[0]);
ThreadUpdater.updateThreadStatus('Closed', postObjects[0]);
nodes = []; nodes = [];
posts = []; posts = [];
index = []; index = [];

View File

@ -20,6 +20,7 @@ beta
There is now a setting to allow expanding spoilers. There is now a setting to allow expanding spoilers.
Thread Updater changes: Thread Updater changes:
The Thread Updater will now notify of sticky/closed status change and update the icons.
The Thread Updater will pause when offline, and resume when online. The Thread Updater will pause when offline, and resume when online.
Added an option to always auto-scroll to the bottom. Added an option to always auto-scroll to the bottom.

View File

@ -3599,9 +3599,38 @@ ThreadUpdater =
ThreadUpdater.req = $.ajax url, onloadend: ThreadUpdater.cb.load, ThreadUpdater.req = $.ajax url, onloadend: ThreadUpdater.cb.load,
headers: 'If-Modified-Since': ThreadUpdater.lastModified headers: 'If-Modified-Since': ThreadUpdater.lastModified
updateThreadStatus: (title, OP) ->
titleLC = title.toLowerCase()
return if ThreadUpdater.thread["is#{title}"] is !!OP[titleLC]
unless ThreadUpdater.thread["is#{title}"] = !!OP[titleLC]
message = if title is 'Sticky'
'The thread is not a sticky anymore.'
else
'The thread is not closed anymore.'
new Notification 'info', message, 30
$.rm $ ".#{titleLC}Icon", ThreadUpdater.thread.OP.nodes.info
return
message = if title is 'Sticky'
'The thread is now a sticky.'
else
'The thread is now closed.'
new Notification 'info', message, 30
icon = $.el 'img',
src: "//static.4chan.org/image/#{titleLC}.gif"
alt: title
title: title
className: "#{titleLC}Icon"
root = $ '[title="Quote this post"]', ThreadUpdater.thread.OP.nodes.info
if title is 'Closed'
root = $('.stickyIcon', ThreadUpdater.thread.OP.nodes.info) or root
$.after root, [$.tn(' '), icon]
parse: (postObjects) -> parse: (postObjects) ->
Build.spoilerRange[ThreadUpdater.thread.board] = postObjects[0].custom_spoiler Build.spoilerRange[ThreadUpdater.thread.board] = postObjects[0].custom_spoiler
ThreadUpdater.updateThreadStatus 'Sticky', postObjects[0]
ThreadUpdater.updateThreadStatus 'Closed', postObjects[0]
nodes = [] # post container elements nodes = [] # post container elements
posts = [] # post objects posts = [] # post objects
index = [] # existing posts index = [] # existing posts