From 384a95163d8568b3b22be26a564b70605e9fa656 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Tue, 26 Feb 2013 18:49:07 +0100 Subject: [PATCH] Get the cooldown start time at the end of the upload, not when we receive a response from the server: shorter cooldown period and faster auto-posting. --- 4chan_x.user.js | 9 +++++---- changelog | 2 ++ src/qr.coffee | 13 +++++++++---- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 489f58af7..f0d23b1e3 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -5849,7 +5849,7 @@ }, set: function(data) { var cooldown, hasFile, isReply, isSage, start, type; - start = Date.now(); + start = data.req ? data.req.uploadEndTime : Date.now(); if (data.delay) { cooldown = { delay: data.delay @@ -5876,15 +5876,14 @@ }, count: function() { var cooldown, cooldowns, elapsed, hasFile, isReply, isSage, now, post, seconds, start, type, types, update, _ref; - if (Object.keys(QR.cooldown.cooldowns).length) { - setTimeout(QR.cooldown.count, 1000); - } else { + if (!Object.keys(QR.cooldown.cooldowns).length) { $["delete"]("" + g.BOARD + ".cooldown"); delete QR.cooldown.isCounting; delete QR.cooldown.seconds; QR.status(); return; } + setTimeout(QR.cooldown.count, 1000); isReply = g.BOARD.ID === 'f' ? g.VIEW === 'thread' : QR.nodes.thread.value !== 'new'; if (isReply) { post = QR.replies[0]; @@ -6615,6 +6614,7 @@ upCallbacks: { onload: function() { QR.req.isUploadFinished = true; + QR.req.uploadEndTime = Date.now(); QR.req.progress = '...'; return QR.status(); }, @@ -6686,6 +6686,7 @@ postID: postID }, QR.nodes.el); QR.cooldown.set({ + req: req, post: reply, isReply: !!threadID }); diff --git a/changelog b/changelog index fed8e0860..a2fe3722c 100644 --- a/changelog +++ b/changelog @@ -16,7 +16,9 @@ beta Delete links in the post menu will only appear for your posts. QR changes: + Cooldown start time is now more accurate, which means shorter cooldown period and faster auto-posting. Clicking the submit button while uploading will abort the upload and won't start re-uploading automatically anymore. + Closing the QR while uploading will abort the upload and won't close the QR anymore. Creating threads outside of the index is now possible. Selection-to-quote also applies to selected text inside the post, not just inside the comment. Quoting the OP will not insert the >>opnumber anymore unless the QR was already opened. diff --git a/src/qr.coffee b/src/qr.coffee index 03272add8..a3c8e7b68 100644 --- a/src/qr.coffee +++ b/src/qr.coffee @@ -159,7 +159,10 @@ QR = QR.cooldown.cooldowns[id] = cooldowns[id] QR.cooldown.start() set: (data) -> - start = Date.now() + start = if data.req + data.req.uploadEndTime + else + Date.now() if data.delay cooldown = delay: data.delay else @@ -186,15 +189,15 @@ QR = delete QR.cooldown.cooldowns[id] $.set "cooldown.#{g.BOARD}", QR.cooldown.cooldowns count: -> - if Object.keys(QR.cooldown.cooldowns).length - setTimeout QR.cooldown.count, 1000 - else + unless Object.keys(QR.cooldown.cooldowns).length $.delete "#{g.BOARD}.cooldown" delete QR.cooldown.isCounting delete QR.cooldown.seconds QR.status() return + setTimeout QR.cooldown.count, 1000 + isReply = if g.BOARD.ID is 'f' g.VIEW is 'thread' else @@ -826,6 +829,7 @@ QR = onload: -> # Upload done, waiting for server response. QR.req.isUploadFinished = true + QR.req.uploadEndTime = Date.now() QR.req.progress = '...' QR.status() onprogress: (e) -> @@ -912,6 +916,7 @@ QR = }, QR.nodes.el QR.cooldown.set + req: req post: reply isReply: !!threadID