diff --git a/4chan_x.user.js b/4chan_x.user.js index 3389b149e..0d459d1a0 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1531,15 +1531,16 @@ $.bind(favicon, 'click', watcher.cb.toggle); $.before(input, favicon); } - watcher.refresh($.getValue('watched', {})); - return setInterval((function() { - if (watcher.lastUpdated < $.getValue('watcher.lastUpdated', 0)) { - return watcher.refresh($.getValue('watched', {})); + watcher.refresh(); + return $.bind(window, 'storage', function(e) { + if (e.key === 'AEOS.4chan_x.watched') { + return watcher.refresh(); } - }), 1000); + }); }, - refresh: function(watched) { - var board, dialog, div, favicon, id, link, props, watchedBoard, x, _i, _j, _len, _len2, _ref, _ref2, _ref3; + refresh: function() { + var board, dialog, div, favicon, id, link, props, watched, watchedBoard, x, _i, _j, _len, _len2, _ref, _ref2, _ref3, _results; + watched = $.getValue('watched', {}); dialog = $('#watcher'); _ref = $$('div:not(.move)', dialog); for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -1562,16 +1563,13 @@ } watchedBoard = watched[g.BOARD] || {}; _ref3 = $$('img.favicon'); + _results = []; for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) { favicon = _ref3[_j]; id = favicon.nextSibling.name; - if (id in watchedBoard) { - favicon.src = Favicon["default"]; - } else { - favicon.src = Favicon.empty; - } + _results.push(id in watchedBoard ? favicon.src = Favicon["default"] : favicon.src = Favicon.empty); } - return watcher.lastUpdated = Date.now(); + return _results; }, cb: { toggle: function(e) { @@ -1598,8 +1596,7 @@ watched = $.getValue('watched', {}); delete watched[board][id]; $.setValue('watched', watched); - watcher.refresh(watched); - return $.setValue('watcher.lastUpdated', Date.now()); + return watcher.refresh(); }, watch: function(thread, id) { var props, tc, watched, _name; @@ -1612,8 +1609,7 @@ watched[_name = g.BOARD] || (watched[_name] = {}); watched[g.BOARD][id] = props; $.setValue('watched', watched); - watcher.refresh(watched); - return $.setValue('watcher.lastUpdated', Date.now()); + return watcher.refresh(); } }; anonymize = { diff --git a/script.coffee b/script.coffee index acac878b2..d023084c9 100644 --- a/script.coffee +++ b/script.coffee @@ -1245,14 +1245,12 @@ watcher = $.before input, favicon #populate watcher, display watch buttons - watcher.refresh $.getValue 'watched', {} + watcher.refresh() - setInterval (-> - if watcher.lastUpdated < $.getValue 'watcher.lastUpdated', 0 - watcher.refresh $.getValue 'watched', {} - ), 1000 + $.bind window, 'storage', (e) -> watcher.refresh() if e.key is 'AEOS.4chan_x.watched' - refresh: (watched) -> + refresh: -> + watched = $.getValue 'watched', {} dialog = $ '#watcher' for div in $$ 'div:not(.move)', dialog $.rm div @@ -1274,7 +1272,6 @@ watcher = favicon.src = Favicon.default else favicon.src = Favicon.empty - watcher.lastUpdated = Date.now() cb: toggle: (e) -> @@ -1296,9 +1293,7 @@ watcher = watched = $.getValue 'watched', {} delete watched[board][id] $.setValue 'watched', watched - - watcher.refresh watched - $.setValue 'watcher.lastUpdated', Date.now() + watcher.refresh() watch: (thread, id) -> tc = $('span.filetitle', thread).textContent or $('blockquote', thread).textContent @@ -1310,9 +1305,7 @@ watcher = watched[g.BOARD] or= {} watched[g.BOARD][id] = props $.setValue 'watched', watched - - watcher.refresh watched - $.setValue 'watcher.lastUpdated', Date.now() + watcher.refresh() anonymize = init: ->