Use xhr.responseType = 'json'.

This commit is contained in:
Mayhem 2014-01-21 14:46:26 +01:00
parent 2ed498813d
commit 710655f13e
11 changed files with 15 additions and 15 deletions

View File

@ -47,6 +47,8 @@ $.ajax = do ->
if whenModified if whenModified
r.setRequestHeader 'If-Modified-Since', lastModified[url] if url of lastModified r.setRequestHeader 'If-Modified-Since', lastModified[url] if url of lastModified
$.on r, 'load', -> lastModified[url] = r.getResponseHeader 'Last-Modified' $.on r, 'load', -> lastModified[url] = r.getResponseHeader 'Last-Modified'
if /\.json$/.test url
r.responseType = 'json'
$.extend r, options $.extend r, options
$.extend r.upload, upCallbacks $.extend r.upload, upCallbacks
r.send form r.send form

View File

@ -37,7 +37,7 @@ Redirect =
return if lastarchivecheck > now - 2 * $.DAY return if lastarchivecheck > now - 2 * $.DAY
$.ajax '<%= meta.page %>json/archives.json', onload: -> $.ajax '<%= meta.page %>json/archives.json', onload: ->
if @status is 200 if @status is 200
Conf['archives'] = JSON.parse @response Conf['archives'] = @response
Redirect.selectArchives() Redirect.selectArchives()
$.set $.set
lastarchivecheck: now lastarchivecheck: now

View File

@ -61,7 +61,7 @@ ThreadHiding =
$.cache "//a.4cdn.org/#{g.BOARD}/threads.json", -> $.cache "//a.4cdn.org/#{g.BOARD}/threads.json", ->
return unless @status is 200 return unless @status is 200
threads = {} threads = {}
for page in JSON.parse @response for page in @response
for thread in page.threads for thread in page.threads
if thread.no of hiddenThreadsOnCatalog if thread.no of hiddenThreadsOnCatalog
threads[thread.no] = hiddenThreadsOnCatalog[thread.no] threads[thread.no] = hiddenThreadsOnCatalog[thread.no]

View File

@ -75,7 +75,7 @@ class DataBoard
return return
board = @data.boards[boardID] board = @data.boards[boardID]
threads = {} threads = {}
for page in JSON.parse e.target.response for page in e.target.response
for thread in page.threads for thread in page.threads
if thread.no of board if thread.no of board
threads[thread.no] = board[thread.no] threads[thread.no] = board[thread.no]

View File

@ -114,7 +114,7 @@ Get =
"Error #{req.statusText} (#{req.status})." "Error #{req.statusText} (#{req.status})."
return return
posts = JSON.parse(req.response).posts {posts} = req.response
Build.spoilerRange[boardID] = posts[0].custom_spoiler Build.spoilerRange[boardID] = posts[0].custom_spoiler
for post in posts for post in posts
break if post.no is postID # we found it! break if post.no is postID # we found it!
@ -145,7 +145,7 @@ Get =
Get.insert post, root, context Get.insert post, root, context
return return
data = JSON.parse req.response data = req.response
if data.error if data.error
$.addClass root, 'warning' $.addClass root, 'warning'
root.textContent = data.error root.textContent = data.error

View File

@ -239,7 +239,7 @@ Index =
try try
if req.status is 200 if req.status is 200
Index.parse JSON.parse(req.response), pageNum Index.parse req.response, pageNum
else if req.status is 304 and pageNum? else if req.status is 304 and pageNum?
Index.pageNav pageNum Index.pageNav pageNum
catch err catch err

View File

@ -135,7 +135,7 @@ ImageExpand =
# XXX CORS for i.4cdn.org WHEN? # XXX CORS for i.4cdn.org WHEN?
$.ajax "//a.4cdn.org/#{post.board}/res/#{post.thread}.json", onload: -> $.ajax "//a.4cdn.org/#{post.board}/res/#{post.thread}.json", onload: ->
return if @status isnt 200 return if @status isnt 200
for postObj in JSON.parse(@response).posts for postObj in @response.posts
break if postObj.no is post.ID break if postObj.no is post.ID
if postObj.no isnt post.ID if postObj.no isnt post.ID
clearTimeout timeoutID clearTimeout timeoutID

View File

@ -41,7 +41,7 @@ ImageHover =
# XXX CORS for i.4cdn.org WHEN? # XXX CORS for i.4cdn.org WHEN?
$.ajax "//a.4cdn.org/#{post.board}/res/#{post.thread}.json", onload: -> $.ajax "//a.4cdn.org/#{post.board}/res/#{post.thread}.json", onload: ->
return if @status isnt 200 return if @status isnt 200
for postObj in JSON.parse(@response).posts for postObj in @response.posts
break if postObj.no is post.ID break if postObj.no is post.ID
if postObj.no isnt post.ID if postObj.no isnt post.ID
clearTimeout timeoutID clearTimeout timeoutID

View File

@ -74,13 +74,12 @@ ExpandThread =
a.textContent = "Error #{req.statusText} (#{req.status})" a.textContent = "Error #{req.statusText} (#{req.status})"
return return
data = JSON.parse(req.response).posts Build.spoilerRange[thread.board] = req.response.posts.shift().custom_spoiler
Build.spoilerRange[thread.board] = data.shift().custom_spoiler
posts = [] posts = []
postsRoot = [] postsRoot = []
filesCount = 0 filesCount = 0
for postData in data for postData in req.response.posts
if post = thread.posts[postData.no] if post = thread.posts[postData.no]
filesCount++ if 'file' of post filesCount++ if 'file' of post
postsRoot.push post.nodes.root postsRoot.push post.nodes.root

View File

@ -41,10 +41,9 @@ ThreadStats =
whenModified: true whenModified: true
onThreadsLoad: -> onThreadsLoad: ->
return if @status isnt 200 return if @status isnt 200
pages = JSON.parse @response for page in @response
for page in pages
for thread in page.threads for thread in page.threads
if thread.no is ThreadStats.thread.ID if thread.no is ThreadStats.thread.ID
ThreadStats.pageCountEl.textContent = page.page ThreadStats.pageCountEl.textContent = page.page
(if page.page is pages.length - 1 then $.addClass else $.rmClass) ThreadStats.pageCountEl, 'warning' (if page.page is @response.length - 1 then $.addClass else $.rmClass) ThreadStats.pageCountEl, 'warning'
return return

View File

@ -98,7 +98,7 @@ ThreadUpdater =
switch req.status switch req.status
when 200 when 200
g.DEAD = false g.DEAD = false
ThreadUpdater.parse JSON.parse(req.response).posts ThreadUpdater.parse req.response.posts
ThreadUpdater.setInterval() ThreadUpdater.setInterval()
when 404 when 404
g.DEAD = true g.DEAD = true