diff --git a/4chan_x.user.js b/4chan_x.user.js index 64bc685e0..e87d0568c 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1531,14 +1531,12 @@ $.before(input, favicon); } watcher.refresh($.getValue('watched', {})); - return setInterval((function() { - if (watcher.lastUpdated < $.getValue('watcher.lastUpdated', 0)) { - return watcher.refresh($.getValue('watched', {})); - } - }), 1000); + return $.bind(window, 'storage', (function() { + return watcher.refresh($.getValue('watched', {})); + })); }, refresh: function(watched) { - var board, dialog, div, favicon, id, link, props, watchedBoard, x, _i, _j, _len, _len2, _ref, _ref2, _ref3; + var board, dialog, div, favicon, id, link, props, watchedBoard, x, _i, _j, _len, _len2, _ref, _ref2, _ref3, _results; dialog = $('#watcher'); _ref = $$('div:not(.move)', dialog); for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -1561,16 +1559,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) { @@ -1597,8 +1592,7 @@ watched = $.getValue('watched', {}); delete watched[board][id]; $.setValue('watched', watched); - watcher.refresh(watched); - return $.setValue('watcher.lastUpdated', Date.now()); + return watcher.refresh(watched); }, watch: function(thread, id) { var props, tc, watched, _name; @@ -1611,8 +1605,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(watched); } }; anonymize = { diff --git a/script.coffee b/script.coffee index a68586a82..08b1e34f4 100644 --- a/script.coffee +++ b/script.coffee @@ -1245,10 +1245,7 @@ watcher = #populate watcher, display watch buttons watcher.refresh $.getValue 'watched', {} - setInterval (-> - if watcher.lastUpdated < $.getValue 'watcher.lastUpdated', 0 - watcher.refresh $.getValue 'watched', {} - ), 1000 + $.bind window, 'storage', (-> watcher.refresh $.getValue 'watched', {}) refresh: (watched) -> dialog = $ '#watcher' @@ -1272,7 +1269,6 @@ watcher = favicon.src = Favicon.default else favicon.src = Favicon.empty - watcher.lastUpdated = Date.now() cb: toggle: (e) -> @@ -1294,9 +1290,7 @@ watcher = watched = $.getValue 'watched', {} delete watched[board][id] $.setValue 'watched', watched - watcher.refresh watched - $.setValue 'watcher.lastUpdated', Date.now() watch: (thread, id) -> tc = $('span.filetitle', thread).textContent or $('blockquote', thread).textContent @@ -1308,9 +1302,7 @@ watcher = watched[g.BOARD] or= {} watched[g.BOARD][id] = props $.setValue 'watched', watched - watcher.refresh watched - $.setValue 'watcher.lastUpdated', Date.now() anonymize = init: ->