diff --git a/4chan_x.user.js b/4chan_x.user.js index b4841e41c..e548ea9b5 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -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) { 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; + ThreadUpdater.updateThreadStatus('Sticky', postObjects[0]); + ThreadUpdater.updateThreadStatus('Closed', postObjects[0]); nodes = []; posts = []; index = []; diff --git a/changelog b/changelog index 3adb79ac4..c5bc5fa05 100644 --- a/changelog +++ b/changelog @@ -20,6 +20,7 @@ beta There is now a setting to allow expanding spoilers. 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. Added an option to always auto-scroll to the bottom. diff --git a/src/features.coffee b/src/features.coffee index 3caa69f75..1b28dedeb 100644 --- a/src/features.coffee +++ b/src/features.coffee @@ -3599,9 +3599,38 @@ ThreadUpdater = ThreadUpdater.req = $.ajax url, onloadend: ThreadUpdater.cb.load, 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) -> Build.spoilerRange[ThreadUpdater.thread.board] = postObjects[0].custom_spoiler + ThreadUpdater.updateThreadStatus 'Sticky', postObjects[0] + ThreadUpdater.updateThreadStatus 'Closed', postObjects[0] + nodes = [] # post container elements posts = [] # post objects index = [] # existing posts