Auto-posting now works!

Try to submit during the cooldown to toggle auto-posting.
It will be automatically activated if you have more than one reply to submit when posting or after posting.
This commit is contained in:
Nicolas Stepien 2012-01-26 02:28:31 +01:00
parent fb3dee8e6e
commit 5d7d13ec70
2 changed files with 55 additions and 30 deletions

View File

@ -1287,7 +1287,7 @@
}
if (!qr.el) return;
input = qr.status.input;
input.value = value || 'Submit';
input.value = qr.cooldown.auto ? value ? "Auto " + value : 'Auto' : value || 'Submit';
return input.disabled = disabled || false;
},
cooldown: {
@ -1312,10 +1312,13 @@
return $.set("/" + g.BOARD + "/cooldown", Date.now() + seconds * SECOND);
},
count: function(seconds) {
if (!((60 >= seconds && seconds >= 0))) return;
if (!((0 <= seconds && seconds <= 60))) return;
setTimeout(qr.cooldown.count, 1000, seconds - 1);
if (seconds === 0) $["delete"]("/" + g.BOARD + "/cooldown");
qr.cooldown.seconds = seconds;
if (seconds === 0) {
$["delete"]("/" + g.BOARD + "/cooldown");
if (qr.cooldown.auto) qr.submit();
}
return qr.status();
}
},
@ -1622,7 +1625,11 @@
submit: function(e) {
var captcha, captchas, challenge, err, file, m, post, reader, reply, response, threadID;
if (e != null) e.preventDefault();
if (qr.cooldown.seconds) return;
if (qr.cooldown.seconds) {
qr.cooldown.auto = !qr.cooldown.auto;
qr.status();
return;
}
qr.message.send({
abort: true
});
@ -1651,7 +1658,8 @@
}
qr.cleanError();
threadID = g.THREAD_ID || $('select', qr.el).value;
if (conf['Auto Hide QR'] && qr.replies.length === 1) qr.hide();
qr.cooldown.auto = qr.replies.length > 1;
if (conf['Auto Hide QR'] && !qr.cooldown.auto) qr.hide();
if (conf['Thread Watcher'] && conf['Auto Watch Reply'] && threadID !== 'new') {
watcher.watch(threadID);
}
@ -1685,7 +1693,6 @@
},
response: function(html) {
var b, err, node, persona, postNumber, reply, thread, _, _ref;
qr.status();
if (!(b = $('td b', $.el('a', {
innerHTML: html
})))) {
@ -1694,18 +1701,18 @@
if (b.firstChild.tagName) node = b.firstChild;
err = b.firstChild.textContent;
if (err === 'You seem to have mistyped the verification.') {
qr.cooldown.auto = !!$.get('captchas', []).length;
qr.cooldown.set(10);
} else {
qr.cooldown.auto = false;
}
}
qr.status();
if (err) {
qr.error(err, node);
return;
}
reply = qr.replies[0];
_ref = b.lastChild.textContent.match(/thread:(\d+),no:(\d+)/), _ = _ref[0], thread = _ref[1], postNumber = _ref[2];
if (thread === 0) {} else {
qr.cooldown.set(/sage/i.test(reply.email) ? 60 : 30);
}
persona = $.get('qr.persona', {});
persona = {
name: reply.name,
@ -1713,7 +1720,12 @@
sub: conf['Remember Subject'] ? reply.sub : null
};
$.set('qr.persona', persona);
if (conf['Persistent QR'] || qr.replies.length > 1) {
_ref = b.lastChild.textContent.match(/thread:(\d+),no:(\d+)/), _ = _ref[0], thread = _ref[1], postNumber = _ref[2];
if (thread === 0) {} else {
qr.cooldown.auto = qr.replies.length > 1;
qr.cooldown.set(/sage/i.test(reply.email) ? 60 : 30);
}
if (conf['Persistent QR'] || qr.cooldown.auto) {
reply.rm();
} else {
qr.close();
@ -1779,7 +1791,7 @@
if (data.status) qr.status(data);
delete data.qr;
if (data.mode === 'regist') {
url = "http://sys.4chan.org/" + data.board + "/post?" + (Date.now());
url = "http://sys.4chan.org/" + data.board + "/post";
delete data.board;
form = new FormData();
if (engine === 'gecko' && data.upfile) {

View File

@ -928,7 +928,11 @@ qr =
value = qr.cooldown.seconds or data.progress or value
return unless qr.el
{input} = qr.status
input.value = value or 'Submit' # dispaly "Auto #{...}" when auto postan
input.value =
if qr.cooldown.auto
if value then "Auto #{value}" else 'Auto'
else
value or 'Submit'
input.disabled = disabled or false
cooldown:
@ -946,12 +950,12 @@ qr =
qr.cooldown.count seconds
$.set "/#{g.BOARD}/cooldown", Date.now() + seconds*SECOND
count: (seconds) ->
return unless 60 >= seconds >= 0
return unless 0 <= seconds <= 60
setTimeout qr.cooldown.count, 1000, seconds-1
qr.cooldown.seconds = seconds
if seconds is 0
$.delete "/#{g.BOARD}/cooldown"
# auto postan
qr.cooldown.seconds = seconds
qr.submit() if qr.cooldown.auto
qr.status()
pickThread: (thread) ->
@ -1192,7 +1196,8 @@ qr =
submit: (e) ->
e?.preventDefault()
if qr.cooldown.seconds
# toggle auto postan
qr.cooldown.auto = !qr.cooldown.auto
qr.status()
return
qr.message.send abort: true
reply = qr.replies[0]
@ -1224,7 +1229,9 @@ qr =
threadID = g.THREAD_ID or $('select', qr.el).value
if conf['Auto Hide QR'] and qr.replies.length is 1
# Enable auto-posting if we have stuff to post, disable it otherwise.
qr.cooldown.auto = qr.replies.length > 1
if conf['Auto Hide QR'] and not qr.cooldown.auto
qr.hide()
if conf['Thread Watcher'] and conf['Auto Watch Reply'] and threadID isnt 'new'
watcher.watch threadID
@ -1260,15 +1267,20 @@ qr =
qr.message.send post
response: (html) ->
qr.status()
unless b = $ 'td b', $.el('a', innerHTML: html)
err = 'Connection error with sys.4chan.org.'
else if b.childElementCount # error!
node = b.firstChild if b.firstChild.tagName # duplicate image link
err = b.firstChild.textContent
if err is 'You seem to have mistyped the verification.'
qr.cooldown.set 10 # prevent autoban
# turn auto postan ON? Might depend if we have captchas in stock or not
# Enable auto-post if we have some cached captchas.
qr.cooldown.auto = !!$.get('captchas', []).length
# Too many frequent mistyped captchas will auto-ban you!
qr.cooldown.set 10
else # stop auto-posting
qr.cooldown.auto = false
qr.status()
if err
qr.error err, node
@ -1276,12 +1288,6 @@ qr =
reply = qr.replies[0]
[_, thread, postNumber] = b.lastChild.textContent.match /thread:(\d+),no:(\d+)/
if thread is 0 # new thread
# auto noko to postNumber
else
qr.cooldown.set if /sage/i.test reply.email then 60 else 30
persona = $.get 'qr.persona', {}
persona =
name: reply.name
@ -1289,7 +1295,15 @@ qr =
sub: if conf['Remember Subject'] then reply.sub else null
$.set 'qr.persona', persona
if conf['Persistent QR'] or qr.replies.length > 1
[_, thread, postNumber] = b.lastChild.textContent.match /thread:(\d+),no:(\d+)/
if thread is 0 # new thread
# auto noko to postNumber
else
# Enable auto-posting if we have stuff to post, disable it otherwise.
qr.cooldown.auto = qr.replies.length > 1
qr.cooldown.set if /sage/i.test reply.email then 60 else 30
if conf['Persistent QR'] or qr.cooldown.auto
reply.rm()
else
qr.close()
@ -1341,8 +1355,7 @@ qr =
qr.status data
delete data.qr
if data.mode is 'regist' # reply object: we're posting
# fool CloudFlare's cache to hopefully avoid connection errors
url = "http://sys.4chan.org/#{data.board}/post?#{Date.now()}"
url = "http://sys.4chan.org/#{data.board}/post"
delete data.board
form = new FormData()
if engine is 'gecko' and data.upfile