From 458f03167b76717c7e2400be7e32554d503b4ece Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 5 May 2011 18:56:12 +0200 Subject: [PATCH] Every second, check if we updated one second before. --- 4chan_x.js | 15 ++++++++++----- script.coffee | 6 +++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index 08772dbc7..05a67438e 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1482,11 +1482,13 @@ } watcher.refresh($.getValue('watched', {})); return setInterval((function() { - return watcher.refresh($.getValue('watched', {})); + if (Date.now() > $.getValue('watcher.lastUpdated', 0)) { + return watcher.refresh($.getValue('watched', {})); + } }), 1000); }, refresh: function(watched) { - var board, div, favicon, id, props, watchedBoard, _i, _j, _len, _len2, _ref, _ref2, _ref3, _results; + var board, div, favicon, id, props, watchedBoard, _i, _j, _len, _len2, _ref, _ref2, _ref3; _ref = $$('#watcher > div:not(.move)'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { div = _ref[_i]; @@ -1501,13 +1503,16 @@ } watchedBoard = watched[g.BOARD] || {}; _ref3 = $$('img.favicon'); - _results = []; for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) { favicon = _ref3[_j]; id = favicon.nextSibling.name; - _results.push(id in watchedBoard ? favicon.src = Favicon["default"] : favicon.src = Favicon.empty); + if (id in watchedBoard) { + favicon.src = Favicon["default"]; + } else { + favicon.src = Favicon.empty; + } } - return _results; + return $.setValue('watcher.lastUpdated', Date.now()); }, addLink: function(props, dialog) { var div, link, x; diff --git a/script.coffee b/script.coffee index b90bb1115..e3760ab50 100644 --- a/script.coffee +++ b/script.coffee @@ -1178,7 +1178,10 @@ watcher = #populate watcher, display watch buttons watcher.refresh $.getValue 'watched', {} - setInterval (-> watcher.refresh($.getValue 'watched', {}) ), 1000 + setInterval (-> + if Date.now() > $.getValue 'watcher.lastUpdated', 0 + watcher.refresh($.getValue 'watched', {}) + ), 1000 refresh: (watched) -> for div in $$ '#watcher > div:not(.move)' @@ -1193,6 +1196,7 @@ watcher = favicon.src = Favicon.default else favicon.src = Favicon.empty + $.setValue 'watcher.lastUpdated', Date.now() addLink: (props, dialog) -> div = $.el 'div'