Fix non-JSON 4chan

This commit is contained in:
Zixaphir 2014-01-13 20:59:37 -07:00
parent 0264edab7d
commit d81c4cd568
3 changed files with 83 additions and 72 deletions

View File

@ -17269,37 +17269,40 @@
} }
}, },
initThread: function() { initThread: function() {
var err, errors, postRoot, posts, thread, threadRoot, _i, _len, _ref; var board, err, errors, postRoot, posts, thread, threadRoot, threads, _i, _j, _len, _len1, _ref, _ref1;
if (!(threadRoot = $('.thread'))) { if (board = $('.board')) {
return; threads = [];
} posts = [];
thread = new Thread(+threadRoot.id.slice(1), g.BOARD); _ref = $$('.board > .thread', board);
posts = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) {
_ref = $$('.thread > .postContainer', threadRoot); threadRoot = _ref[_i];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { thread = new Thread(+threadRoot.id.slice(1), g.BOARD);
postRoot = _ref[_i]; threads.push(thread);
try { _ref1 = $$('.thread > .postContainer', threadRoot);
posts.push(new Post(postRoot, thread, g.BOARD, { for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
isOriginalMarkup: true postRoot = _ref1[_j];
})); try {
} catch (_error) { posts.push(new Post(postRoot, thread, g.BOARD));
err = _error; } catch (_error) {
if (!errors) { err = _error;
errors = []; 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) { callbackNodes: function(klass, nodes) {
var cb, i, node; var cb, i, node;

View File

@ -17246,37 +17246,40 @@
} }
}, },
initThread: function() { initThread: function() {
var err, errors, postRoot, posts, thread, threadRoot, _i, _len, _ref; var board, err, errors, postRoot, posts, thread, threadRoot, threads, _i, _j, _len, _len1, _ref, _ref1;
if (!(threadRoot = $('.thread'))) { if (board = $('.board')) {
return; threads = [];
} posts = [];
thread = new Thread(+threadRoot.id.slice(1), g.BOARD); _ref = $$('.board > .thread', board);
posts = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) {
_ref = $$('.thread > .postContainer', threadRoot); threadRoot = _ref[_i];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { thread = new Thread(+threadRoot.id.slice(1), g.BOARD);
postRoot = _ref[_i]; threads.push(thread);
try { _ref1 = $$('.thread > .postContainer', threadRoot);
posts.push(new Post(postRoot, thread, g.BOARD, { for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
isOriginalMarkup: true postRoot = _ref1[_j];
})); try {
} catch (_error) { posts.push(new Post(postRoot, thread, g.BOARD));
err = _error; } catch (_error) {
if (!errors) { err = _error;
errors = []; 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) { callbackNodes: function(klass, nodes) {
var cb, i, node; var cb, i, node;

View File

@ -141,23 +141,28 @@ Main =
new Notice 'warning', 'Cookies need to be enabled on 4chan for <%= meta.name %> to operate properly.', 30 new Notice 'warning', 'Cookies need to be enabled on 4chan for <%= meta.name %> to operate properly.', 30
initThread: -> initThread: ->
return unless threadRoot = $ '.thread' if board = $ '.board'
thread = new Thread +threadRoot.id[1..], g.BOARD threads = []
posts = [] 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
Main.callbackNodes Thread, [thread] for threadRoot in $$ '.board > .thread', board
Main.callbackNodesDB Post, posts, -> thread = new Thread +threadRoot.id[1..], g.BOARD
$.event '4chanXInitFinished' 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) -> callbackNodes: (klass, nodes) ->
i = 0 i = 0