fix #49, cooldown
This commit is contained in:
parent
a3676597d2
commit
06ae1b66bf
57
4chan_x.js
57
4chan_x.js
@ -998,6 +998,7 @@
|
|||||||
$.remove(dialog);
|
$.remove(dialog);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
qr.cooldown(true);
|
||||||
}
|
}
|
||||||
Recaptcha.reload();
|
Recaptcha.reload();
|
||||||
return $('iframe[name=iframe]').src = 'about:blank';
|
return $('iframe[name=iframe]').src = 'about:blank';
|
||||||
@ -1021,9 +1022,8 @@
|
|||||||
$.remove(span);
|
$.remove(span);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (g.seconds = $.getValue('seconds')) {
|
if (qr.cooldown()) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
qr.cooldownStart();
|
|
||||||
alert('Stop posting so often!');
|
alert('Stop posting so often!');
|
||||||
if (isQR) {
|
if (isQR) {
|
||||||
span = $.el('span', {
|
span = $.el('span', {
|
||||||
@ -1036,7 +1036,7 @@
|
|||||||
}
|
}
|
||||||
recaptcha = $('input[name=recaptcha_response_field]', this);
|
recaptcha = $('input[name=recaptcha_response_field]', this);
|
||||||
if (recaptcha.value) {
|
if (recaptcha.value) {
|
||||||
g.sage = $('input[name=email]', form).value === 'sage';
|
qr.sage = $('input[name=email]', form).value === 'sage';
|
||||||
if (isQR) {
|
if (isQR) {
|
||||||
return qr.autohide.set();
|
return qr.autohide.set();
|
||||||
}
|
}
|
||||||
@ -1085,34 +1085,50 @@
|
|||||||
f = $('input[type=file]', dialog).parentNode;
|
f = $('input[type=file]', dialog).parentNode;
|
||||||
return f.innerHTML = f.innerHTML;
|
return f.innerHTML = f.innerHTML;
|
||||||
},
|
},
|
||||||
cooldown: function() {
|
cooldown: function(restart) {
|
||||||
|
var duration, end, now;
|
||||||
|
now = Date.now();
|
||||||
|
if (restart) {
|
||||||
|
duration = qr.sage ? 60 : 30;
|
||||||
|
qr.cooldownStart(duration);
|
||||||
|
$.setValue("" + g.BOARD + "/cooldown", now + duration * 1000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
end = $.getValue("" + g.BOARD + "/cooldown", 0);
|
||||||
|
if (now < end) {
|
||||||
|
duration = Math.ceil((end - now) / 1000);
|
||||||
|
qr.cooldownStart(duration);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
cooldownStart: function(duration) {
|
||||||
var submit, submits, _i, _len;
|
var submit, submits, _i, _len;
|
||||||
submits = $$('#qr input[type=submit], form[name=post] input[type=submit]');
|
submits = $$('#qr input[type=submit], form[name=post] input[type=submit]');
|
||||||
for (_i = 0, _len = submits.length; _i < _len; _i++) {
|
for (_i = 0, _len = submits.length; _i < _len; _i++) {
|
||||||
submit = submits[_i];
|
submit = submits[_i];
|
||||||
if (g.seconds === 0) {
|
submit.value = duration;
|
||||||
|
submit.disabled = true;
|
||||||
|
}
|
||||||
|
qr.cooldownIntervalID = window.setInterval(qr.cooldownCB, 1000);
|
||||||
|
return qr.duration = duration;
|
||||||
|
},
|
||||||
|
cooldownCB: function() {
|
||||||
|
var submit, submits, _i, _len;
|
||||||
|
qr.duration = qr.duration - 1;
|
||||||
|
submits = $$('#qr input[type=submit], form[name=post] input[type=submit]');
|
||||||
|
for (_i = 0, _len = submits.length; _i < _len; _i++) {
|
||||||
|
submit = submits[_i];
|
||||||
|
if (qr.duration === 0) {
|
||||||
submit.disabled = false;
|
submit.disabled = false;
|
||||||
submit.value = 'Submit';
|
submit.value = 'Submit';
|
||||||
} else {
|
} else {
|
||||||
submit.value = g.seconds = g.seconds - 1;
|
submit.value = qr.duration;
|
||||||
$.setValue('seconds', g.seconds);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (g.seconds !== 0) {
|
if (qr.duration === 0) {
|
||||||
return window.setTimeout(qr.cooldown, 1000);
|
return clearInterval(qr.cooldownIntervalID);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
cooldownStart: function() {
|
|
||||||
var submit, submits, _i, _len;
|
|
||||||
$.setValue('seconds', g.seconds);
|
|
||||||
submits = $$('#qr input[type=submit], form[name=post] input[type=submit]');
|
|
||||||
for (_i = 0, _len = submits.length; _i < _len; _i++) {
|
|
||||||
submit = submits[_i];
|
|
||||||
submit.value = g.seconds;
|
|
||||||
submit.disabled = true;
|
|
||||||
}
|
|
||||||
return window.setTimeout(qr.cooldown, 1000);
|
|
||||||
},
|
|
||||||
dialog: function(link) {
|
dialog: function(link) {
|
||||||
var clone, dialog, el, html, resto, script, xpath, _i, _len, _ref;
|
var clone, dialog, el, html, resto, script, xpath, _i, _len, _ref;
|
||||||
html = "<div class=move>Quick Reply <input type=checkbox title=autohide> <a name=close title=close>X</a></div>";
|
html = "<div class=move>Quick Reply <input type=checkbox title=autohide> <a name=close title=close>X</a></div>";
|
||||||
@ -2096,6 +2112,7 @@
|
|||||||
$.addStyle(main.css);
|
$.addStyle(main.css);
|
||||||
Recaptcha.init();
|
Recaptcha.init();
|
||||||
$.bind($('form[name=post]'), 'submit', qr.cb.submit);
|
$.bind($('form[name=post]'), 'submit', qr.cb.submit);
|
||||||
|
qr.cooldown();
|
||||||
if ($.config('Image Expansion')) {
|
if ($.config('Image Expansion')) {
|
||||||
imgExpand.init();
|
imgExpand.init();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -743,12 +743,13 @@ qr =
|
|||||||
textContent: data
|
textContent: data
|
||||||
$.append dialog, error
|
$.append dialog, error
|
||||||
qr.autohide.unset()
|
qr.autohide.unset()
|
||||||
else
|
else # success
|
||||||
if dialog
|
if dialog
|
||||||
if $.config 'Persistent QR'
|
if $.config 'Persistent QR'
|
||||||
qr.refresh dialog
|
qr.refresh dialog
|
||||||
else
|
else
|
||||||
$.remove dialog
|
$.remove dialog
|
||||||
|
qr.cooldown true
|
||||||
|
|
||||||
Recaptcha.reload()
|
Recaptcha.reload()
|
||||||
$('iframe[name=iframe]').src = 'about:blank'
|
$('iframe[name=iframe]').src = 'about:blank'
|
||||||
@ -766,9 +767,9 @@ qr =
|
|||||||
if span = @nextSibling
|
if span = @nextSibling
|
||||||
$.remove span
|
$.remove span
|
||||||
|
|
||||||
if g.seconds = $.getValue 'seconds'
|
# check if we've posted on this board in another tab
|
||||||
|
if qr.cooldown()
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
qr.cooldownStart()
|
|
||||||
alert 'Stop posting so often!'
|
alert 'Stop posting so often!'
|
||||||
|
|
||||||
if isQR
|
if isQR
|
||||||
@ -781,7 +782,7 @@ qr =
|
|||||||
|
|
||||||
recaptcha = $('input[name=recaptcha_response_field]', this)
|
recaptcha = $('input[name=recaptcha_response_field]', this)
|
||||||
if recaptcha.value
|
if recaptcha.value
|
||||||
g.sage = $('input[name=email]', form).value == 'sage'
|
qr.sage = $('input[name=email]', form).value == 'sage'
|
||||||
if isQR
|
if isQR
|
||||||
qr.autohide.set()
|
qr.autohide.set()
|
||||||
else
|
else
|
||||||
@ -825,26 +826,42 @@ qr =
|
|||||||
f = $('input[type=file]', dialog).parentNode
|
f = $('input[type=file]', dialog).parentNode
|
||||||
f.innerHTML = f.innerHTML
|
f.innerHTML = f.innerHTML
|
||||||
|
|
||||||
cooldown: ->
|
cooldown: (restart) ->
|
||||||
|
now = Date.now()
|
||||||
|
|
||||||
|
if restart
|
||||||
|
duration = if qr.sage then 60 else 30
|
||||||
|
qr.cooldownStart duration
|
||||||
|
$.setValue "#{g.BOARD}/cooldown", now + duration * 1000
|
||||||
|
return
|
||||||
|
|
||||||
|
end = $.getValue "#{g.BOARD}/cooldown", 0
|
||||||
|
if now < end
|
||||||
|
duration = Math.ceil (end - now) / 1000
|
||||||
|
qr.cooldownStart duration
|
||||||
|
return true
|
||||||
|
|
||||||
|
cooldownStart: (duration) ->
|
||||||
submits = $$ '#qr input[type=submit], form[name=post] input[type=submit]'
|
submits = $$ '#qr input[type=submit], form[name=post] input[type=submit]'
|
||||||
for submit in submits
|
for submit in submits
|
||||||
if g.seconds == 0
|
submit.value = duration
|
||||||
|
submit.disabled = true
|
||||||
|
qr.cooldownIntervalID = window.setInterval qr.cooldownCB, 1000
|
||||||
|
qr.duration = duration
|
||||||
|
|
||||||
|
cooldownCB: ->
|
||||||
|
qr.duration = qr.duration - 1
|
||||||
|
|
||||||
|
submits = $$ '#qr input[type=submit], form[name=post] input[type=submit]'
|
||||||
|
for submit in submits
|
||||||
|
if qr.duration == 0
|
||||||
submit.disabled = false
|
submit.disabled = false
|
||||||
submit.value = 'Submit'
|
submit.value = 'Submit'
|
||||||
else
|
else
|
||||||
submit.value = g.seconds = g.seconds - 1
|
submit.value = qr.duration
|
||||||
$.setValue 'seconds', g.seconds
|
|
||||||
|
|
||||||
if g.seconds != 0
|
if qr.duration == 0
|
||||||
window.setTimeout qr.cooldown, 1000
|
clearInterval qr.cooldownIntervalID
|
||||||
|
|
||||||
cooldownStart: ->
|
|
||||||
$.setValue 'seconds', g.seconds
|
|
||||||
submits = $$ '#qr input[type=submit], form[name=post] input[type=submit]'
|
|
||||||
for submit in submits
|
|
||||||
submit.value = g.seconds
|
|
||||||
submit.disabled = true
|
|
||||||
window.setTimeout qr.cooldown, 1000
|
|
||||||
|
|
||||||
dialog: (link) ->
|
dialog: (link) ->
|
||||||
html = "<div class=move>Quick Reply <input type=checkbox title=autohide> <a name=close title=close>X</a></div>"
|
html = "<div class=move>Quick Reply <input type=checkbox title=autohide> <a name=close title=close>X</a></div>"
|
||||||
@ -1608,6 +1625,8 @@ main =
|
|||||||
|
|
||||||
$.bind $('form[name=post]'), 'submit', qr.cb.submit
|
$.bind $('form[name=post]'), 'submit', qr.cb.submit
|
||||||
|
|
||||||
|
qr.cooldown()
|
||||||
|
|
||||||
#major features
|
#major features
|
||||||
if $.config 'Image Expansion'
|
if $.config 'Image Expansion'
|
||||||
imgExpand.init()
|
imgExpand.init()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user