From b62d82bed059e885931ce1fc7c7bc578d3fa416e Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Fri, 24 Jan 2014 14:48:39 -0700 Subject: [PATCH] Mayhem made responseType JSON default for any URL containing .json. --- LICENSE | 2 +- builds/4chan-X.user.js | 20 ++++++++++---------- builds/crx/script.js | 20 ++++++++++---------- src/General/Navigate.coffee | 11 +++-------- src/Images/Gallery.coffee | 3 ++- src/Linkification/Linkify.coffee | 4 ++-- 6 files changed, 28 insertions(+), 32 deletions(-) diff --git a/LICENSE b/LICENSE index f1b5fcfd6..486b179bc 100755 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ /* -* 4chan X - Version 1.3.2 - 2014-01-22 +* 4chan X - Version 1.3.2 - 2014-01-24 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index fb5c69793..27835f28c 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -23,7 +23,7 @@ // ==/UserScript== /* -* 4chan X - Version 1.3.2 - 2014-01-22 +* 4chan X - Version 1.3.2 - 2014-01-24 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE @@ -7431,12 +7431,13 @@ } return $.ajax("//api.4chan.org/" + post.board + "/res/" + post.thread + ".json", { onload: function() { - var i, postObj; + var i, postObj, posts; if (this.status !== 200) { return; } i = 0; - while (postObj = JSON.parse(this.response).posts[i++]) { + posts = this.response.posts; + while (postObj = posts[i++]) { if (postObj.no === post.ID) { break; } @@ -8261,7 +8262,7 @@ switch (response.status) { case 200: case 304: - text = "" + (service.text(JSON.parse(response.responseText))); + text = "" + (service.text(response.response)); if (Conf['Embedding']) { embed.dataset.title = text; } @@ -8357,7 +8358,7 @@ if (status !== 200 && status !== 304) { return div.innerHTML = "ERROR " + status; } - files = JSON.parse(this.response).files; + files = this.response.files; _ref = ['video/mp4', 'video/ogv', 'image/svg+xml', 'image/png', 'image/gif', 'image/jpeg', 'image/svg', 'audio/mpeg']; for (_i = 0, _len = _ref.length; _i < _len; _i++) { type = _ref[_i]; @@ -12155,13 +12156,13 @@ } }, clean: function() { - var posts, threads; - posts = g.posts, threads = g.threads; + var board; g.threads.forEach(function(thread) { return thread.collect(); }); QuoteBacklink.containers = {}; - return $.rmAll($('.board')); + board = $('.board'); + return $.replace(board, board.cloneNode(false)); }, features: [['Thread Excerpt', ThreadExcerpt], ['Unread Count', Unread], ['Quote Threading', QuoteThreading], ['Thread Stats', ThreadStats], ['Thread Updater', ThreadUpdater], ['Thread Expansion', ExpandThread]], disconnect: function() { @@ -12260,7 +12261,6 @@ }, updateBoard: function(boardID) { var fullBoardList, onload, req; - req = null; fullBoardList = $('#full-board-list', Header.boardList); $.rmClass($('.current', fullBoardList), 'current'); $.addClass($("a[href*='/" + boardID + "/']", fullBoardList), 'current'); @@ -12276,7 +12276,7 @@ return; } try { - _ref = JSON.parse(req.response).boards; + _ref = req.response.boards; for (_i = 0, _len = _ref.length; _i < _len; _i++) { aboard = _ref[_i]; if (!(aboard.board === boardID)) { diff --git a/builds/crx/script.js b/builds/crx/script.js index 29ffaa95d..3fd4559a2 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript /* -* 4chan X - Version 1.3.2 - 2014-01-22 +* 4chan X - Version 1.3.2 - 2014-01-24 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE @@ -7446,12 +7446,13 @@ } return $.ajax("//api.4chan.org/" + post.board + "/res/" + post.thread + ".json", { onload: function() { - var i, postObj; + var i, postObj, posts; if (this.status !== 200) { return; } i = 0; - while (postObj = JSON.parse(this.response).posts[i++]) { + posts = this.response.posts; + while (postObj = posts[i++]) { if (postObj.no === post.ID) { break; } @@ -8254,7 +8255,7 @@ switch (response.status) { case 200: case 304: - text = "" + (service.text(JSON.parse(response.responseText))); + text = "" + (service.text(response.response)); if (Conf['Embedding']) { embed.dataset.title = text; } @@ -8350,7 +8351,7 @@ if (status !== 200 && status !== 304) { return div.innerHTML = "ERROR " + status; } - files = JSON.parse(this.response).files; + files = this.response.files; _ref = ['video/mp4', 'video/ogv', 'image/svg+xml', 'image/png', 'image/gif', 'image/jpeg', 'image/svg', 'audio/mpeg']; for (_i = 0, _len = _ref.length; _i < _len; _i++) { type = _ref[_i]; @@ -12154,13 +12155,13 @@ } }, clean: function() { - var posts, threads; - posts = g.posts, threads = g.threads; + var board; g.threads.forEach(function(thread) { return thread.collect(); }); QuoteBacklink.containers = {}; - return $.rmAll($('.board')); + board = $('.board'); + return $.replace(board, board.cloneNode(false)); }, features: [['Thread Excerpt', ThreadExcerpt], ['Unread Count', Unread], ['Quote Threading', QuoteThreading], ['Thread Stats', ThreadStats], ['Thread Updater', ThreadUpdater], ['Thread Expansion', ExpandThread]], disconnect: function() { @@ -12259,7 +12260,6 @@ }, updateBoard: function(boardID) { var fullBoardList, onload, req; - req = null; fullBoardList = $('#full-board-list', Header.boardList); $.rmClass($('.current', fullBoardList), 'current'); $.addClass($("a[href*='/" + boardID + "/']", fullBoardList), 'current'); @@ -12275,7 +12275,7 @@ return; } try { - _ref = JSON.parse(req.response).boards; + _ref = req.response.boards; for (_i = 0, _len = _ref.length; _i < _len; _i++) { aboard = _ref[_i]; if (!(aboard.board === boardID)) { diff --git a/src/General/Navigate.coffee b/src/General/Navigate.coffee index 541b9efb8..d37f664df 100644 --- a/src/General/Navigate.coffee +++ b/src/General/Navigate.coffee @@ -33,15 +33,12 @@ Navigate = return clean: -> - {posts, threads} = g - # Garbage collection g.threads.forEach (thread) -> thread.collect() - QuoteBacklink.containers = {} - # Delete nodes - $.rmAll $ '.board' + board = $('.board') + $.replace board, board.cloneNode false features: [ ['Thread Excerpt', ThreadExcerpt] @@ -112,8 +109,6 @@ Navigate = }[g.VIEW]() updateBoard: (boardID) -> - req = null - fullBoardList = $ '#full-board-list', Header.boardList $.rmClass $('.current', fullBoardList), 'current' $.addClass $("a[href*='/#{boardID}/']", fullBoardList), 'current' @@ -129,7 +124,7 @@ Navigate = return unless req.status is 200 try - for aboard in JSON.parse(req.response).boards when aboard.board is boardID + for aboard in req.response.boards when aboard.board is boardID board = aboard break diff --git a/src/Images/Gallery.coffee b/src/Images/Gallery.coffee index 472792115..03215608c 100644 --- a/src/Images/Gallery.coffee +++ b/src/Images/Gallery.coffee @@ -201,7 +201,8 @@ Gallery = $.ajax "//api.4chan.org/#{post.board}/res/#{post.thread}.json", onload: -> return if @status isnt 200 i = 0 - while postObj = JSON.parse(@response).posts[i++] + {posts} = @response + while postObj = posts[i++] break if postObj.no is post.ID unless postObj.no return post.kill() diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index 6774be36e..4f27bcc35 100755 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -241,7 +241,7 @@ Linkify = service = Linkify.types[key].title switch response.status when 200, 304 - text = "#{service.text JSON.parse response.responseText}" + text = "#{service.text response.response}" if Conf['Embedding'] embed.dataset.title = text when 404 @@ -304,7 +304,7 @@ Linkify = $.cache "https://mediacru.sh/#{a.dataset.uid}.json", -> {status} = @ return div.innerHTML = "ERROR #{status}" unless status in [200, 304] - {files} = JSON.parse @response + {files} = @response for type in ['video/mp4', 'video/ogv', 'image/svg+xml', 'image/png', 'image/gif', 'image/jpeg', 'image/svg', 'audio/mpeg'] for file in files if file.type is type