From d81c4cd568609215a5123e8c96a72dc4ffeb4a41 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Mon, 13 Jan 2014 20:59:37 -0700 Subject: [PATCH] Fix non-JSON 4chan --- builds/appchan-x.user.js | 59 +++++++++++++++++++++------------------- builds/crx/script.js | 59 +++++++++++++++++++++------------------- src/General/Main.coffee | 37 ++++++++++++++----------- 3 files changed, 83 insertions(+), 72 deletions(-) diff --git a/builds/appchan-x.user.js b/builds/appchan-x.user.js index d549fe7ca..c9535c7b1 100644 --- a/builds/appchan-x.user.js +++ b/builds/appchan-x.user.js @@ -17269,37 +17269,40 @@ } }, initThread: function() { - var err, errors, postRoot, posts, thread, threadRoot, _i, _len, _ref; - if (!(threadRoot = $('.thread'))) { - return; - } - thread = new Thread(+threadRoot.id.slice(1), g.BOARD); - posts = []; - _ref = $$('.thread > .postContainer', threadRoot); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - postRoot = _ref[_i]; - try { - posts.push(new Post(postRoot, thread, g.BOARD, { - isOriginalMarkup: true - })); - } catch (_error) { - err = _error; - if (!errors) { - errors = []; + var board, err, errors, postRoot, posts, thread, threadRoot, threads, _i, _j, _len, _len1, _ref, _ref1; + if (board = $('.board')) { + threads = []; + posts = []; + _ref = $$('.board > .thread', board); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + threadRoot = _ref[_i]; + thread = new Thread(+threadRoot.id.slice(1), g.BOARD); + threads.push(thread); + _ref1 = $$('.thread > .postContainer', threadRoot); + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + postRoot = _ref1[_j]; + try { + posts.push(new Post(postRoot, thread, g.BOARD)); + } catch (_error) { + err = _error; + if (!errors) { + errors = []; + } + errors.push({ + message: "Parsing of Post No." + (postRoot.id.match(/\d+/)) + " failed. Post will be skipped.", + error: err + }); + } } - errors.push({ - message: "Parsing of Post No." + (postRoot.id.match(/\d+/)) + " failed. Post will be skipped.", - error: err - }); } + if (errors) { + Main.handleErrors(errors); + } + Main.callbackNodes(Thread, threads); + return Main.callbackNodesDB(Post, posts, function() { + return $.event('4chanXInitFinished'); + }); } - if (errors) { - Main.handleErrors(errors); - } - Main.callbackNodes(Thread, [thread]); - return Main.callbackNodesDB(Post, posts, function() { - return $.event('4chanXInitFinished'); - }); }, callbackNodes: function(klass, nodes) { var cb, i, node; diff --git a/builds/crx/script.js b/builds/crx/script.js index 91cf52701..893f4e483 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -17246,37 +17246,40 @@ } }, initThread: function() { - var err, errors, postRoot, posts, thread, threadRoot, _i, _len, _ref; - if (!(threadRoot = $('.thread'))) { - return; - } - thread = new Thread(+threadRoot.id.slice(1), g.BOARD); - posts = []; - _ref = $$('.thread > .postContainer', threadRoot); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - postRoot = _ref[_i]; - try { - posts.push(new Post(postRoot, thread, g.BOARD, { - isOriginalMarkup: true - })); - } catch (_error) { - err = _error; - if (!errors) { - errors = []; + var board, err, errors, postRoot, posts, thread, threadRoot, threads, _i, _j, _len, _len1, _ref, _ref1; + if (board = $('.board')) { + threads = []; + posts = []; + _ref = $$('.board > .thread', board); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + threadRoot = _ref[_i]; + thread = new Thread(+threadRoot.id.slice(1), g.BOARD); + threads.push(thread); + _ref1 = $$('.thread > .postContainer', threadRoot); + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + postRoot = _ref1[_j]; + try { + posts.push(new Post(postRoot, thread, g.BOARD)); + } catch (_error) { + err = _error; + if (!errors) { + errors = []; + } + errors.push({ + message: "Parsing of Post No." + (postRoot.id.match(/\d+/)) + " failed. Post will be skipped.", + error: err + }); + } } - errors.push({ - message: "Parsing of Post No." + (postRoot.id.match(/\d+/)) + " failed. Post will be skipped.", - error: err - }); } + if (errors) { + Main.handleErrors(errors); + } + Main.callbackNodes(Thread, threads); + return Main.callbackNodesDB(Post, posts, function() { + return $.event('4chanXInitFinished'); + }); } - if (errors) { - Main.handleErrors(errors); - } - Main.callbackNodes(Thread, [thread]); - return Main.callbackNodesDB(Post, posts, function() { - return $.event('4chanXInitFinished'); - }); }, callbackNodes: function(klass, nodes) { var cb, i, node; diff --git a/src/General/Main.coffee b/src/General/Main.coffee index fb35cc8e0..52b3a7527 100644 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -141,23 +141,28 @@ Main = new Notice 'warning', 'Cookies need to be enabled on 4chan for <%= meta.name %> to operate properly.', 30 initThread: -> - return unless threadRoot = $ '.thread' - thread = new Thread +threadRoot.id[1..], g.BOARD - posts = [] - for postRoot in $$ '.thread > .postContainer', threadRoot - try - posts.push new Post postRoot, thread, g.BOARD, {isOriginalMarkup: true} - catch err - # Skip posts that we failed to parse. - errors = [] unless errors - errors.push - message: "Parsing of Post No.#{postRoot.id.match /\d+/} failed. Post will be skipped." - error: err - Main.handleErrors errors if errors + if board = $ '.board' + threads = [] + posts = [] - Main.callbackNodes Thread, [thread] - Main.callbackNodesDB Post, posts, -> - $.event '4chanXInitFinished' + for threadRoot in $$ '.board > .thread', board + thread = new Thread +threadRoot.id[1..], g.BOARD + threads.push thread + for postRoot in $$ '.thread > .postContainer', threadRoot + try + posts.push new Post postRoot, thread, g.BOARD + catch err + # Skip posts that we failed to parse. + unless errors + errors = [] + errors.push + message: "Parsing of Post No.#{postRoot.id.match(/\d+/)} failed. Post will be skipped." + error: err + Main.handleErrors errors if errors + + Main.callbackNodes Thread, threads + Main.callbackNodesDB Post, posts, -> + $.event '4chanXInitFinished' callbackNodes: (klass, nodes) -> i = 0