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

View File

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