Do the math, once.

This commit is contained in:
Nicolas Stepien 2011-06-04 00:55:02 +02:00
parent 296fb027ec
commit 6edb57796d
2 changed files with 18 additions and 21 deletions

View File

@ -1021,26 +1021,25 @@
}; };
cooldown = { cooldown = {
init: function() { init: function() {
var duration; if (Date.now() < $.getValue(g.BOARD + '/cooldown', 0)) {
if (0 < (duration = Math.ceil(($.getValue(g.BOARD + '/cooldown', 0) - Date.now()) / 1000))) { cooldown.start();
cooldown.start(duration);
} }
return $.bind(window, 'storage', function(e) { return $.bind(window, 'storage', function(e) {
if (e.key === ("AEOS.4chan_x." + g.BOARD + "/cooldown")) { if (e.key === ("AEOS.4chan_x." + g.BOARD + "/cooldown")) {
return cooldown.start(Math.ceil(($.getValue(g.BOARD + '/cooldown', 0) - Date.now()) / 1000)); return cooldown.start();
} }
}); });
}, },
start: function(duration) { start: function() {
var submit, _i, _len, _ref; var submit, _i, _len, _ref;
cooldown.duration = Math.ceil(($.getValue(g.BOARD + '/cooldown', 0) - Date.now()) / 1000);
_ref = $$('#com_submit'); _ref = $$('#com_submit');
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
submit = _ref[_i]; submit = _ref[_i];
submit.value = duration; submit.value = cooldown.duration;
submit.disabled = true; submit.disabled = true;
} }
cooldown.interval = window.setInterval(cooldown.cb, 1000); return cooldown.interval = window.setInterval(cooldown.cb, 1000);
return cooldown.duration = duration;
}, },
cb: function() { cb: function() {
var submit, _i, _len, _ref; var submit, _i, _len, _ref;
@ -1107,9 +1106,9 @@
} }
} }
if ($.config('Cooldown')) { if ($.config('Cooldown')) {
duration = qr.sage ? 60 : 30; duration = qr.sage ? 60000 : 30000;
$.setValue(g.BOARD + '/cooldown', Date.now() + duration * 1000); $.setValue(g.BOARD + '/cooldown', Date.now() + duration);
cooldown.start(duration); cooldown.start();
} }
} }
Recaptcha.reload(); Recaptcha.reload();

View File

@ -780,17 +780,15 @@ options =
cooldown = cooldown =
init: -> init: ->
if 0 < duration = Math.ceil ($.getValue(g.BOARD+'/cooldown', 0) - Date.now()) / 1000 cooldown.start() if Date.now() < $.getValue g.BOARD+'/cooldown', 0
cooldown.start duration $.bind window, 'storage', (e) -> cooldown.start() if e.key is "AEOS.4chan_x.#{g.BOARD}/cooldown"
$.bind window, 'storage', (e) -> if e.key is "AEOS.4chan_x.#{g.BOARD}/cooldown"
cooldown.start Math.ceil ($.getValue(g.BOARD+'/cooldown', 0) - Date.now()) / 1000
start: (duration) -> start: ->
cooldown.duration = Math.ceil ($.getValue(g.BOARD+'/cooldown', 0) - Date.now()) / 1000
for submit in $$ '#com_submit' for submit in $$ '#com_submit'
submit.value = duration submit.value = cooldown.duration
submit.disabled = true submit.disabled = true
cooldown.interval = window.setInterval cooldown.cb, 1000 cooldown.interval = window.setInterval cooldown.cb, 1000
cooldown.duration = duration
cb: -> cb: ->
cooldown.duration-- cooldown.duration--
@ -842,9 +840,9 @@ qr =
else else
$.rm dialog $.rm dialog
if $.config 'Cooldown' if $.config 'Cooldown'
duration = if qr.sage then 60 else 30 duration = if qr.sage then 60000 else 30000
$.setValue g.BOARD+'/cooldown', Date.now() + duration * 1000 $.setValue g.BOARD+'/cooldown', Date.now() + duration
cooldown.start duration cooldown.start()
Recaptcha.reload() Recaptcha.reload()
$('iframe[name=iframe]').src = 'about:blank' $('iframe[name=iframe]').src = 'about:blank'