Merge pull request #174 from MayhemYDG/cooldown
Bind cooldown storage events.
This commit is contained in:
commit
581eada263
105
4chan_x.user.js
105
4chan_x.user.js
@ -59,7 +59,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var $, $$, Favicon, NAMESPACE, Recaptcha, anonymize, config, d, expandComment, expandThread, g, imageHover, imgExpand, imgGif, imgPreloading, keybinds, localize, log, main, nav, nodeInserted, options, qr, quoteBacklink, quoteInline, quoteOP, quotePreview, redirect, replyHiding, reportButton, sauce, threadHiding, threadStats, threading, titlePost, ui, unread, updater, watcher, _config, _ref;
|
var $, $$, Favicon, NAMESPACE, Recaptcha, anonymize, config, cooldown, d, expandComment, expandThread, g, imageHover, imgExpand, imgGif, imgPreloading, keybinds, localize, log, main, nav, nodeInserted, options, qr, quoteBacklink, quoteInline, quoteOP, quotePreview, redirect, replyHiding, reportButton, sauce, threadHiding, threadStats, threading, titlePost, ui, unread, updater, watcher, _config, _ref;
|
||||||
var __slice = Array.prototype.slice;
|
var __slice = Array.prototype.slice;
|
||||||
if (typeof console !== "undefined" && console !== null) {
|
if (typeof console !== "undefined" && console !== null) {
|
||||||
log = function(arg) {
|
log = function(arg) {
|
||||||
@ -1019,6 +1019,46 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
cooldown = {
|
||||||
|
init: function() {
|
||||||
|
if (Date.now() < $.getValue(g.BOARD + '/cooldown', 0)) {
|
||||||
|
cooldown.start();
|
||||||
|
}
|
||||||
|
return $.bind(window, 'storage', function(e) {
|
||||||
|
if (e.key === ("AEOS.4chan_x." + g.BOARD + "/cooldown")) {
|
||||||
|
return cooldown.start();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
start: function() {
|
||||||
|
var submit, _i, _len, _ref;
|
||||||
|
cooldown.duration = Math.ceil(($.getValue(g.BOARD + '/cooldown', 0) - Date.now()) / 1000);
|
||||||
|
_ref = $$('#com_submit');
|
||||||
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
|
submit = _ref[_i];
|
||||||
|
submit.value = cooldown.duration;
|
||||||
|
submit.disabled = true;
|
||||||
|
}
|
||||||
|
return cooldown.interval = window.setInterval(cooldown.cb, 1000);
|
||||||
|
},
|
||||||
|
cb: function() {
|
||||||
|
var submit, _i, _len, _ref;
|
||||||
|
cooldown.duration--;
|
||||||
|
_ref = $$('#com_submit');
|
||||||
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
|
submit = _ref[_i];
|
||||||
|
if (cooldown.duration) {
|
||||||
|
submit.value = cooldown.duration;
|
||||||
|
} else {
|
||||||
|
submit.disabled = false;
|
||||||
|
submit.value = 'Submit';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!cooldown.duration) {
|
||||||
|
return window.clearInterval(cooldown.interval);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
qr = {
|
qr = {
|
||||||
init: function() {
|
init: function() {
|
||||||
var iframe;
|
var iframe;
|
||||||
@ -1051,7 +1091,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
message: function(e) {
|
message: function(e) {
|
||||||
var data, dialog;
|
var data, dialog, duration;
|
||||||
data = e.data;
|
data = e.data;
|
||||||
dialog = $('#qr');
|
dialog = $('#qr');
|
||||||
if (data) {
|
if (data) {
|
||||||
@ -1066,7 +1106,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($.config('Cooldown')) {
|
if ($.config('Cooldown')) {
|
||||||
qr.cooldown(true);
|
duration = qr.sage ? 60 : 30;
|
||||||
|
$.setValue(g.BOARD + '/cooldown', Date.now() + duration * 1000);
|
||||||
|
cooldown.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Recaptcha.reload();
|
Recaptcha.reload();
|
||||||
@ -1095,17 +1137,6 @@
|
|||||||
if (isQR) {
|
if (isQR) {
|
||||||
$('#error').textContent = '';
|
$('#error').textContent = '';
|
||||||
}
|
}
|
||||||
if ($.config('Cooldown')) {
|
|
||||||
if (qr.cooldown()) {
|
|
||||||
e.preventDefault();
|
|
||||||
if (isQR) {
|
|
||||||
$('#error').textContent = 'Stop posting so often!';
|
|
||||||
} else {
|
|
||||||
alert('Stop posting so often!');
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
qr.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();
|
||||||
@ -1143,50 +1174,6 @@
|
|||||||
f = $('input[type=file]', dialog).parentNode;
|
f = $('input[type=file]', dialog).parentNode;
|
||||||
return f.innerHTML = f.innerHTML;
|
return f.innerHTML = f.innerHTML;
|
||||||
},
|
},
|
||||||
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;
|
|
||||||
submits = $$('#com_submit');
|
|
||||||
for (_i = 0, _len = submits.length; _i < _len; _i++) {
|
|
||||||
submit = submits[_i];
|
|
||||||
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--;
|
|
||||||
submits = $$('#com_submit');
|
|
||||||
for (_i = 0, _len = submits.length; _i < _len; _i++) {
|
|
||||||
submit = submits[_i];
|
|
||||||
if (qr.duration) {
|
|
||||||
submit.value = qr.duration;
|
|
||||||
} else {
|
|
||||||
submit.disabled = false;
|
|
||||||
submit.value = 'Submit';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!qr.duration) {
|
|
||||||
return window.clearInterval(qr.cooldownIntervalID);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
dialog: function(link) {
|
dialog: function(link) {
|
||||||
var MAX_FILE_SIZE, THREAD_ID, c, challenge, dialog, html, m, mail, name, pass, spoiler, src, submitDisabled, submitValue;
|
var MAX_FILE_SIZE, THREAD_ID, c, challenge, dialog, html, m, mail, name, pass, spoiler, src, submitDisabled, submitValue;
|
||||||
MAX_FILE_SIZE = $('input[name="MAX_FILE_SIZE"]').value;
|
MAX_FILE_SIZE = $('input[name="MAX_FILE_SIZE"]').value;
|
||||||
@ -2435,7 +2422,7 @@
|
|||||||
$.bind(form, 'submit', qr.cb.submit);
|
$.bind(form, 'submit', qr.cb.submit);
|
||||||
}
|
}
|
||||||
if ($.config('Cooldown')) {
|
if ($.config('Cooldown')) {
|
||||||
qr.cooldown();
|
cooldown.init();
|
||||||
}
|
}
|
||||||
if ($.config('Image Expansion')) {
|
if ($.config('Image Expansion')) {
|
||||||
imgExpand.init();
|
imgExpand.init();
|
||||||
|
|||||||
@ -778,6 +778,30 @@ options =
|
|||||||
@value = "hidden: 0"
|
@value = "hidden: 0"
|
||||||
g.hiddenReplies = {}
|
g.hiddenReplies = {}
|
||||||
|
|
||||||
|
cooldown =
|
||||||
|
init: ->
|
||||||
|
cooldown.start() if Date.now() < $.getValue g.BOARD+'/cooldown', 0
|
||||||
|
$.bind window, 'storage', (e) -> cooldown.start() if e.key is "AEOS.4chan_x.#{g.BOARD}/cooldown"
|
||||||
|
|
||||||
|
start: ->
|
||||||
|
cooldown.duration = Math.ceil ($.getValue(g.BOARD+'/cooldown', 0) - Date.now()) / 1000
|
||||||
|
for submit in $$ '#com_submit'
|
||||||
|
submit.value = cooldown.duration
|
||||||
|
submit.disabled = true
|
||||||
|
cooldown.interval = window.setInterval cooldown.cb, 1000
|
||||||
|
|
||||||
|
cb: ->
|
||||||
|
cooldown.duration--
|
||||||
|
|
||||||
|
for submit in $$ '#com_submit'
|
||||||
|
if cooldown.duration
|
||||||
|
submit.value = cooldown.duration
|
||||||
|
else
|
||||||
|
submit.disabled = false
|
||||||
|
submit.value = 'Submit'
|
||||||
|
|
||||||
|
window.clearInterval cooldown.interval unless cooldown.duration
|
||||||
|
|
||||||
qr =
|
qr =
|
||||||
init: ->
|
init: ->
|
||||||
g.callbacks.push qr.cb.node
|
g.callbacks.push qr.cb.node
|
||||||
@ -816,7 +840,9 @@ qr =
|
|||||||
else
|
else
|
||||||
$.rm dialog
|
$.rm dialog
|
||||||
if $.config 'Cooldown'
|
if $.config 'Cooldown'
|
||||||
qr.cooldown true
|
duration = if qr.sage then 60 else 30
|
||||||
|
$.setValue g.BOARD+'/cooldown', Date.now() + duration * 1000
|
||||||
|
cooldown.start()
|
||||||
|
|
||||||
Recaptcha.reload()
|
Recaptcha.reload()
|
||||||
$('iframe[name=iframe]').src = 'about:blank'
|
$('iframe[name=iframe]').src = 'about:blank'
|
||||||
@ -841,18 +867,6 @@ qr =
|
|||||||
if isQR
|
if isQR
|
||||||
$('#error').textContent = ''
|
$('#error').textContent = ''
|
||||||
|
|
||||||
if $.config 'Cooldown'
|
|
||||||
# check if we've posted on this board in another tab
|
|
||||||
if qr.cooldown()
|
|
||||||
e.preventDefault()
|
|
||||||
|
|
||||||
if isQR
|
|
||||||
$('#error').textContent = 'Stop posting so often!'
|
|
||||||
else
|
|
||||||
alert 'Stop posting so often!'
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
qr.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()
|
||||||
@ -887,43 +901,6 @@ qr =
|
|||||||
f = $('input[type=file]', dialog).parentNode
|
f = $('input[type=file]', dialog).parentNode
|
||||||
f.innerHTML = f.innerHTML
|
f.innerHTML = f.innerHTML
|
||||||
|
|
||||||
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 = $$ '#com_submit'
|
|
||||||
for submit in submits
|
|
||||||
submit.value = duration
|
|
||||||
submit.disabled = true
|
|
||||||
qr.cooldownIntervalID = window.setInterval qr.cooldownCB, 1000
|
|
||||||
qr.duration = duration
|
|
||||||
|
|
||||||
cooldownCB: ->
|
|
||||||
qr.duration--
|
|
||||||
|
|
||||||
submits = $$ '#com_submit'
|
|
||||||
for submit in submits
|
|
||||||
if qr.duration
|
|
||||||
submit.value = qr.duration
|
|
||||||
else
|
|
||||||
submit.disabled = false
|
|
||||||
submit.value = 'Submit'
|
|
||||||
|
|
||||||
window.clearInterval qr.cooldownIntervalID unless qr.duration
|
|
||||||
|
|
||||||
|
|
||||||
dialog: (link) ->
|
dialog: (link) ->
|
||||||
#maybe should be global
|
#maybe should be global
|
||||||
MAX_FILE_SIZE = $('input[name="MAX_FILE_SIZE"]').value
|
MAX_FILE_SIZE = $('input[name="MAX_FILE_SIZE"]').value
|
||||||
@ -1847,7 +1824,7 @@ main =
|
|||||||
|
|
||||||
#major features
|
#major features
|
||||||
if $.config 'Cooldown'
|
if $.config 'Cooldown'
|
||||||
qr.cooldown()
|
cooldown.init()
|
||||||
|
|
||||||
if $.config 'Image Expansion'
|
if $.config 'Image Expansion'
|
||||||
imgExpand.init()
|
imgExpand.init()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user