From 8357c51c3b05c28b5d473f66b60ce57467bd55b7 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 22 Jul 2011 02:53:19 +0200 Subject: [PATCH] Cache updater's interval, for integers. --- 4chan_x.user.js | 22 +++++++++++++--------- script.coffee | 19 +++++++++++-------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 7a0bf5430..d6994888a 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1561,9 +1561,9 @@ }; updater = { init: function() { - var autoUpT, checked, conf, dialog, html, input, interva, interval, name, title, updNow, verbose, _i, _len, _ref; - interval = $.config('Interval'); - html = "
-" + interval + "
"; + var autoUpT, checked, conf, dialog, html, input, interva, name, title, updNow, verbose, _i, _len, _ref; + updater.interval = $.config('Interval'); + html = "
-" + updater.interval + "
"; conf = config.updater.checkbox; for (name in conf) { title = conf[name][1]; @@ -1571,7 +1571,7 @@ html += "
"; } checked = $.config('Auto Update') ? 'checked' : ''; - html += "
"; + html += "
"; dialog = ui.dialog('updater', { bottom: '0', right: '0' @@ -1587,7 +1587,7 @@ updNow = $('input[type=button]', dialog); $.bind(verbose, 'click', updater.cb.verbose); $.bind(autoUpT, 'click', updater.cb.autoUpdate); - $.bind(interva, 'change', $.cb.value); + $.bind(interva, 'change', updater.cb.interval); $.bind(updNow, 'click', updater.updateNow); updater.count = $('#count', dialog); updater.timer = $('#timer', dialog); @@ -1596,7 +1596,7 @@ return updater.cb.autoUpdate.call(autoUpT); }, cb: { - verbose: function(e) { + verbose: function() { if (this.checked) { updater.count.textContent = '+0'; return $.show(updater.timer); @@ -1608,14 +1608,18 @@ return $.hide(updater.timer); } }, - autoUpdate: function(e) { + autoUpdate: function() { if (this.checked) { return updater.intervalID = window.setInterval(updater.timeout, 1000); } else { return window.clearInterval(updater.intervalID); } }, - update: function(e) { + interval: function() { + updater.interval = this.value = this.value.match(/\d+/)[0]; + return $.cb.value.call(this); + }, + update: function() { var arr, body, br, id, input, replies, reply, _i, _len, _ref, _ref2; if (this.status === 404) { updater.timer.textContent = ''; @@ -1643,7 +1647,7 @@ while ((reply = replies.pop()) && (reply.id > id)) { arr.push(reply.parentNode.parentNode.parentNode); } - updater.timer.textContent = '-' + $.config('Interval'); + updater.timer.textContent = '-' + updater.interval; if ($.config('Verbose')) { updater.count.textContent = '+' + arr.length; if (arr.length === 0) { diff --git a/script.coffee b/script.coffee index f3221332e..0d3124724 100644 --- a/script.coffee +++ b/script.coffee @@ -1266,8 +1266,8 @@ threadHiding = updater = init: -> - interval = $.config 'Interval' - html = "
-#{interval}
" + updater.interval = $.config 'Interval' + html = "
-#{updater.interval}
" conf = config.updater.checkbox for name of conf title = conf[name][1] @@ -1277,7 +1277,7 @@ updater = checked = if $.config 'Auto Update' then 'checked' else '' html += "
-
+
" dialog = ui.dialog 'updater', bottom: '0', right: '0', html @@ -1291,7 +1291,7 @@ updater = updNow = $ 'input[type=button]', dialog $.bind verbose, 'click', updater.cb.verbose $.bind autoUpT, 'click', updater.cb.autoUpdate - $.bind interva, 'change', $.cb.value + $.bind interva, 'change', updater.cb.interval $.bind updNow, 'click', updater.updateNow updater.count = $ '#count', dialog @@ -1303,7 +1303,7 @@ updater = updater.cb.autoUpdate.call autoUpT cb: - verbose: (e) -> + verbose: -> if @checked updater.count.textContent = '+0' $.show updater.timer @@ -1312,12 +1312,15 @@ updater = className: '' textContent: 'Thread Updater' $.hide updater.timer - autoUpdate: (e) -> + autoUpdate: -> if @checked updater.intervalID = window.setInterval updater.timeout, 1000 else window.clearInterval updater.intervalID - update: (e) -> + interval: -> + updater.interval = @value = @value.match(/\d+/)[0] + $.cb.value.call @ + update: -> if @status is 404 updater.timer.textContent = '' updater.count.textContent = 404 @@ -1341,7 +1344,7 @@ updater = while (reply = replies.pop()) and (reply.id > id) arr.push reply.parentNode.parentNode.parentNode #table - updater.timer.textContent = '-' + $.config 'Interval' + updater.timer.textContent = '-' + updater.interval if $.config 'Verbose' updater.count.textContent = '+' + arr.length if arr.length is 0