From bbe93eb475a956c46b6d9b6f225b03e2f40317f8 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Wed, 7 Aug 2013 15:24:21 +0200 Subject: [PATCH 1/3] Shave a line. --- src/Monitoring/Unread.coffee | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Monitoring/Unread.coffee b/src/Monitoring/Unread.coffee index c31c63b56..da1419be5 100644 --- a/src/Monitoring/Unread.coffee +++ b/src/Monitoring/Unread.coffee @@ -125,9 +125,8 @@ Unread = break if bottom > height # post is not completely read return unless i - Unread.lastReadPost = Unread.posts[i - 1].ID + Unread.lastReadPost = Unread.posts.splice(0, i)[i - 1].ID Unread.saveLastReadPost() - Unread.posts.splice 0, i Unread.readArray Unread.postsQuotingYou Unread.update() if e From 39f30c1d0edbec684c03d199a4466f26ba7a84a2 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Wed, 7 Aug 2013 19:55:25 +0200 Subject: [PATCH 2/3] Slightly simplify $.ajax. --- lib/$.coffee | 14 +++----------- src/General/Main.coffee | 2 +- src/Menu/DeleteLink.coffee | 2 +- src/Posting/QR.coffee | 8 ++++---- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/lib/$.coffee b/lib/$.coffee index 59e08cbbd..306eba722 100644 --- a/lib/$.coffee +++ b/lib/$.coffee @@ -36,23 +36,15 @@ $.extend = (object, properties) -> for key, val of properties object[key] = val return -$.ajax = (url, callbacks, opts={}) -> - {type, cred, headers, upCallbacks, form, sync} = opts +$.ajax = (url, options, extra={}) -> + {type, headers, upCallbacks, form, sync} = extra r = new XMLHttpRequest() type or= form and 'post' or 'get' r.open type, url, !sync for key, val of headers r.setRequestHeader key, val - $.extend r, callbacks + $.extend r, options $.extend r.upload, upCallbacks - try - # Firefox throws an error if you try - # to set this on a synchronous XHR. - # Only cookies from the remote domain - # are used in a request withCredentials. - r.withCredentials = cred - catch err - # do nothing r.send form r $.cache = do -> diff --git a/src/General/Main.coffee b/src/General/Main.coffee index 0105d43f6..a1dd45ae4 100644 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -345,7 +345,7 @@ Main = <% } %> ).join '\n' return unless errors - $.ajax '<%= meta.page %>errors', {}, + $.ajax '<%= meta.page %>errors', null, sync: true form: $.formData n: "<%= meta.name %> v#{g.VERSION}" diff --git a/src/Menu/DeleteLink.coffee b/src/Menu/DeleteLink.coffee index 7f71d7f6e..b7678e48a 100644 --- a/src/Menu/DeleteLink.coffee +++ b/src/Menu/DeleteLink.coffee @@ -55,10 +55,10 @@ DeleteLink = link = @ $.ajax $.id('delform').action.replace("/#{g.BOARD}/", "/#{post.board}/"), + withCredentials: true onload: -> DeleteLink.load link, post, fileOnly, @response onerror: -> DeleteLink.error link , - cred: true form: $.formData form load: (link, post, fileOnly, html) -> tmpDoc = d.implementation.createHTMLDocument '' diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index 791e7ded0..6a1d339d9 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -959,7 +959,8 @@ QR = recaptcha_challenge_field: challenge recaptcha_response_field: response - callbacks = + options = + withCredentials: true onload: QR.response onerror: -> # Connection error, or @@ -973,8 +974,7 @@ QR = Connection error. You may have been banned. [FAQ] """ - opts = - cred: true + extra = form: $.formData postData upCallbacks: onload: -> @@ -988,7 +988,7 @@ QR = QR.req.progress = "#{Math.round e.loaded / e.total * 100}%" QR.status() - QR.req = $.ajax $.id('postForm').parentNode.action, callbacks, opts + QR.req = $.ajax $.id('postForm').parentNode.action, options, extra # Starting to upload might take some time. # Provide some feedback that we're starting to submit. QR.req.uploadStartTime = Date.now() From 773f2cfe0fadb90ff31b9b703bbccc529e19905b Mon Sep 17 00:00:00 2001 From: Mayhem Date: Wed, 7 Aug 2013 20:04:47 +0200 Subject: [PATCH 3/3] Use xhr.responseType = 'document'. --- src/Menu/DeleteLink.coffee | 11 +++++------ src/Posting/QR.coffee | 26 +++++++++++++++----------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/Menu/DeleteLink.coffee b/src/Menu/DeleteLink.coffee index b7678e48a..1912733c6 100644 --- a/src/Menu/DeleteLink.coffee +++ b/src/Menu/DeleteLink.coffee @@ -55,21 +55,20 @@ DeleteLink = link = @ $.ajax $.id('delform').action.replace("/#{g.BOARD}/", "/#{post.board}/"), + responseType: 'document' withCredentials: true onload: -> DeleteLink.load link, post, fileOnly, @response onerror: -> DeleteLink.error link , form: $.formData form - load: (link, post, fileOnly, html) -> - tmpDoc = d.implementation.createHTMLDocument '' - tmpDoc.documentElement.innerHTML = html - if tmpDoc.title is '4chan - Banned' # Ban/warn check + load: (link, post, fileOnly, resDoc) -> + if resDoc.title is '4chan - Banned' # Ban/warn check s = 'Banned!' - else if msg = tmpDoc.getElementById 'errmsg' # error! + else if msg = resDoc.getElementById 'errmsg' # error! s = msg.textContent $.on link, 'click', DeleteLink.delete else - if tmpDoc.title is 'Updating index...' + if resDoc.title is 'Updating index...' # We're 100% sure. (post.origin or post).kill fileOnly s = 'Deleted' diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index 6a1d339d9..fc7b0357b 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -960,6 +960,7 @@ QR = recaptcha_response_field: response options = + responseType: 'document' withCredentials: true onload: QR.response onerror: -> @@ -1002,20 +1003,23 @@ QR = post = QR.posts[0] post.unlock() - tmpDoc = d.implementation.createHTMLDocument '' - tmpDoc.documentElement.innerHTML = req.response - if ban = $ '.banType', tmpDoc # banned/warning - board = $('.board', tmpDoc).innerHTML + resDoc = req.response + if ban = $ '.banType', resDoc # banned/warning + board = $('.board', resDoc).innerHTML err = $.el 'span', innerHTML: if ban.textContent.toLowerCase() is 'banned' - "You are banned on #{board}! ;_;
" + - "Click here to see the reason." + """ + You are banned on #{board}! ;_;
+ Click here to see the reason. + """ else - "You were issued a warning on #{board} as #{$('.nameBlock', tmpDoc).innerHTML}.
" + - "Reason: #{$('.reason', tmpDoc).innerHTML}" - else if err = tmpDoc.getElementById 'errmsg' # error! + """ + You were issued a warning on #{board} as #{$('.nameBlock', resDoc).innerHTML}.
+ Reason: #{$('.reason', resDoc).innerHTML} + """ + else if err = resDoc.getElementById 'errmsg' # error! $('a', err)?.target = '_blank' # duplicate image link - else if tmpDoc.title isnt 'Post successful!' + else if resDoc.title isnt 'Post successful!' err = 'Connection error with sys.4chan.org.' else if req.status isnt 200 err = "Error #{req.statusText} (#{req.status})" @@ -1049,7 +1053,7 @@ QR = QR.error err return - h1 = $ 'h1', tmpDoc + h1 = $ 'h1', resDoc QR.cleanNotifications() QR.notifications.push new Notification 'success', h1.textContent, 5