From 6968bbac81ab93f1171af71239a6bd72517e8c65 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Wed, 25 Mar 2015 19:55:38 -0700 Subject: [PATCH] Work around delayed thread creation issue. #362 --- src/Posting/QR.coffee | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index 4997c4fd9..fae04f21a 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -762,13 +762,33 @@ QR = "#{window.location.origin}/#{g.BOARD}/thread/#{threadID}#p#{postID}" if URL - if Conf['Open Post in New Tab'] or postsCount - $.open URL + open = if Conf['Open Post in New Tab'] or postsCount + -> $.open URL else - window.location = URL + -> window.location = URL + + if threadID is postID + # XXX 4chan sometimes responds before the thread exists. + QR.waitForThread URL, open + else + open() QR.status() + waitForThread: (url, cb) -> + attempts = 0 + check = -> + $.ajax url, + onloadend: -> + attempts++ + if attempts >= 5 or @status is 200 + cb() + else + setTimeout check, attempts * $.SECOND + , + type: 'HEAD' + check() + abort: -> if QR.req and !QR.req.isUploadFinished QR.req.abort()