diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index e2d01a629..00c6d3cac 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -12620,25 +12620,6 @@ Main.handleErrors(errors); } }, - ready: function(name, feature, condition) { - var err, error; - try { - if (condition) { - feature(); - } - } catch (_error) { - err = _error; - error = [ - { - message: "" + name + " Failed.", - error: err - } - ]; - } - if (error) { - return Main.handleErrors(error); - } - }, updateContext: function(view) { g.DEAD = false; if (view === 'thread') { @@ -12773,9 +12754,7 @@ $.set('Index Sort', Conf['Index Sort'] = Index.selectSort.value = indexSort); Index.cb.sort(); } - if (view === g.VIEW && boardID === g.BOARD.ID) { - Navigate.updateContext(view); - } else { + if (!(view === 'index' && 'index' === g.VIEW && boardID === g.BOARD.ID)) { Navigate.disconnect(); Navigate.updateContext(view); Navigate.clean(); @@ -12839,12 +12818,12 @@ } }, parse: function(data) { - var OP, board, errors, makePost, obj, post, posts, thread, threadRoot, _i, _len; - board = g.BOARD; - Navigate.threadRoot = threadRoot = Build.thread(board, OP = data.shift(), true); - thread = new Thread(OP.no, board); + var OP, board, errors, i, makePost, obj, post, posts, thread, threadRoot; posts = []; errors = null; + board = g.BOARD; + threadRoot = Build.thread(board, OP = data[0], true); + thread = new Thread(OP.no, board); makePost = function(postNode) { var err; try { @@ -12855,35 +12834,33 @@ errors = []; } return errors.push({ - message: "Parsing of Post No." + thread.ID + " failed. Post will be skipped.", + message: "Parsing of Post No." + postNode.ID + " failed. Post will be skipped.", error: err }); } }; makePost($('.opContainer', threadRoot)); - for (_i = 0, _len = data.length; _i < _len; _i++) { - obj = data[_i]; + i = 0; + while (obj = data[++i]) { post = Build.postFromObject(obj, board); makePost(post); $.add(threadRoot, post); } - if (errors) { - Main.handleErrors(errors); - } Main.callbackNodes(Thread, [thread]); Main.callbackNodes(Post, posts); - Navigate.ready('Quote Threading', QuoteThreading.force, Conf['Quote Threading'] && !Conf['Unread Count']); - Navigate.buildThread(); - QR.generatePostableThreadsList(); - return Header.hashScroll.call(window); - }, - buildThread: function() { - var board; + if (Conf['Quote Threading'] && !Conf['Unread Count']) { + QuoteThreading.force(); + } board = $('.board'); $.rmAll(board); - $.add(board, [Navigate.threadRoot, $.el('hr')]); + $.add(board, [threadRoot, $.el('hr')]); if (Conf['Unread Count']) { - return Navigate.ready('Unread Count', Unread.ready, Conf['Unread Count']); + Unread.ready(); + } + QR.generatePostableThreadsList(); + Header.hashScroll.call(window); + if (errors) { + return Main.handleErrors(errors); } }, popstate: function() { diff --git a/builds/crx/script.js b/builds/crx/script.js index 992fb0b5c..7d44b7b83 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -12634,25 +12634,6 @@ Main.handleErrors(errors); } }, - ready: function(name, feature, condition) { - var err, error; - try { - if (condition) { - feature(); - } - } catch (_error) { - err = _error; - error = [ - { - message: "" + name + " Failed.", - error: err - } - ]; - } - if (error) { - return Main.handleErrors(error); - } - }, updateContext: function(view) { g.DEAD = false; if (view === 'thread') { @@ -12787,9 +12768,7 @@ $.set('Index Sort', Conf['Index Sort'] = Index.selectSort.value = indexSort); Index.cb.sort(); } - if (view === g.VIEW && boardID === g.BOARD.ID) { - Navigate.updateContext(view); - } else { + if (!(view === 'index' && 'index' === g.VIEW && boardID === g.BOARD.ID)) { Navigate.disconnect(); Navigate.updateContext(view); Navigate.clean(); @@ -12853,12 +12832,12 @@ } }, parse: function(data) { - var OP, board, errors, makePost, obj, post, posts, thread, threadRoot, _i, _len; - board = g.BOARD; - Navigate.threadRoot = threadRoot = Build.thread(board, OP = data.shift(), true); - thread = new Thread(OP.no, board); + var OP, board, errors, i, makePost, obj, post, posts, thread, threadRoot; posts = []; errors = null; + board = g.BOARD; + threadRoot = Build.thread(board, OP = data[0], true); + thread = new Thread(OP.no, board); makePost = function(postNode) { var err; try { @@ -12869,35 +12848,33 @@ errors = []; } return errors.push({ - message: "Parsing of Post No." + thread.ID + " failed. Post will be skipped.", + message: "Parsing of Post No." + postNode.ID + " failed. Post will be skipped.", error: err }); } }; makePost($('.opContainer', threadRoot)); - for (_i = 0, _len = data.length; _i < _len; _i++) { - obj = data[_i]; + i = 0; + while (obj = data[++i]) { post = Build.postFromObject(obj, board); makePost(post); $.add(threadRoot, post); } - if (errors) { - Main.handleErrors(errors); - } Main.callbackNodes(Thread, [thread]); Main.callbackNodes(Post, posts); - Navigate.ready('Quote Threading', QuoteThreading.force, Conf['Quote Threading'] && !Conf['Unread Count']); - Navigate.buildThread(); - QR.generatePostableThreadsList(); - return Header.hashScroll.call(window); - }, - buildThread: function() { - var board; + if (Conf['Quote Threading'] && !Conf['Unread Count']) { + QuoteThreading.force(); + } board = $('.board'); $.rmAll(board); - $.add(board, [Navigate.threadRoot, $.el('hr')]); + $.add(board, [threadRoot, $.el('hr')]); if (Conf['Unread Count']) { - return Navigate.ready('Unread Count', Unread.ready, Conf['Unread Count']); + Unread.ready(); + } + QR.generatePostableThreadsList(); + Header.hashScroll.call(window); + if (errors) { + return Main.handleErrors(errors); } }, popstate: function() { diff --git a/src/General/Navigate.coffee b/src/General/Navigate.coffee index f67ea5ac3..6649b7be9 100644 --- a/src/General/Navigate.coffee +++ b/src/General/Navigate.coffee @@ -75,16 +75,6 @@ Navigate = Main.handleErrors errors if errors return - ready: (name, feature, condition) -> - try - feature() if condition - catch err - error = [ - message: "#{name} Failed." - error: err - ] - Main.handleErrors error if error - updateContext: (view) -> g.DEAD = false g.THREADID = +window.location.pathname.split('/')[3] if view is 'thread' @@ -198,10 +188,7 @@ Navigate = $.set 'Index Sort', Conf['Index Sort'] = Index.selectSort.value = indexSort Index.cb.sort() - if view is g.VIEW and boardID is g.BOARD.ID - Navigate.updateContext view - - else # We've navigated somewhere we weren't before! + unless view is 'index' and 'index' is g.VIEW and boardID is g.BOARD.ID Navigate.disconnect() Navigate.updateContext view Navigate.clean() @@ -258,12 +245,11 @@ Navigate = return parse: (data) -> - board = g.BOARD - Navigate.threadRoot = threadRoot = Build.thread board, OP = data.shift(), true - thread = new Thread OP.no, board - - posts = [] - errors = null + posts = [] + errors = null + board = g.BOARD + threadRoot = Build.thread board, OP = data[0], true + thread = new Thread OP.no, board makePost = (postNode) -> try @@ -272,34 +258,32 @@ Navigate = # Skip posts that we failed to parse. errors = [] unless errors errors.push - message: "Parsing of Post No.#{thread.ID} failed. Post will be skipped." + message: "Parsing of Post No.#{postNode.ID} failed. Post will be skipped." error: err makePost $('.opContainer', threadRoot) - for obj in data + i = 0 + while obj = data[++i] post = Build.postFromObject obj, board makePost post $.add threadRoot, post - Main.handleErrors errors if errors - Main.callbackNodes Thread, [thread] Main.callbackNodes Post, posts - Navigate.ready 'Quote Threading', QuoteThreading.force, Conf['Quote Threading'] and not Conf['Unread Count'] + QuoteThreading.force() if Conf['Quote Threading'] and not Conf['Unread Count'] + + board = $ '.board' + $.rmAll board + $.add board, [threadRoot, $.el 'hr'] + + Unread.ready() if Conf['Unread Count'] - Navigate.buildThread() QR.generatePostableThreadsList() Header.hashScroll.call window - buildThread: -> - board = $ '.board' - $.rmAll board - $.add board, [Navigate.threadRoot, $.el 'hr'] - - if Conf['Unread Count'] - Navigate.ready 'Unread Count', Unread.ready, Conf['Unread Count'] + Main.handleErrors errors if errors popstate: -> return if window.location.pathname is Navigate.path