From 1900bbfa2746323c5126a8e110e1771e81277a4b Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Fri, 10 Jan 2014 23:41:09 -0700 Subject: [PATCH] Fix Unread Count with JSON features --- builds/4chan-X.user.js | 50 +++++++++++++------------------------ builds/crx/script.js | 50 +++++++++++++------------------------ src/General/Navigate.coffee | 36 +++++++++----------------- 3 files changed, 46 insertions(+), 90 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 95559749f..45b27e806 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -11943,28 +11943,23 @@ Main.handleErrors(errors); } }, - ready: function() { - var condition, err, errors, feature, name, _i, _len, _ref, _ref1; - _ref = [['Unread Count', Unread, Conf['Unread Count']], ['Quote Threading', QuoteThreading, Conf['Quote Threading'] && !Conf['Unread Count']]]; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - _ref1 = _ref[_i], name = _ref1[0], feature = _ref1[1], condition = _ref1[2]; - try { - if (condition) { - feature.ready(); - } - } catch (_error) { - err = _error; - if (!errors) { - errors = []; - } - errors.push({ - message: "Failed to reconnect feature " + name + ".", - error: err - }); + ready: function(name, feature, condition) { + var err, error; + try { + if (condition) { + feature(); } + } catch (_error) { + err = _error; + error = [ + { + message: "Quote Threading Failed.", + error: err + } + ]; } - if (errors) { - Main.handleErrors(errors); + if (error) { + Main.handleErrors(error); } return QR.generatePostableThreadsList(); }, @@ -12170,7 +12165,7 @@ } Main.callbackNodes(Thread, [thread]); Main.callbackNodes(Post, posts); - Navigate.ready(); + Navigate.ready('Quote Threading', QuoteThreading.force, Conf['Quote Threading']); return Navigate.buildThread(); }, buildThread: function() { @@ -12179,6 +12174,7 @@ $.rmAll(board); $.add(board, Navigate.threadRoot); if (Conf['Unread Count']) { + Navigate.ready('Unread Count', Unread.ready, Conf['Unread Count']); Unread.read(); return Unread.update(); } @@ -12190,18 +12186,6 @@ id: 'popState' }); return Navigate.navigate.call(a); - }, - refresh: function(context) { - var boardID, feature, name, threadID, view, _i, _len, _ref, _ref1; - return; - boardID = context.boardID, view = context.view, threadID = context.threadID; - _ref = Main.features; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - _ref1 = _ref[_i], name = _ref1[0], feature = _ref1[1]; - if (feature.refresh) { - feature.refresh(); - } - } } }; diff --git a/builds/crx/script.js b/builds/crx/script.js index 9d44de773..067e2c79c 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -11932,28 +11932,23 @@ Main.handleErrors(errors); } }, - ready: function() { - var condition, err, errors, feature, name, _i, _len, _ref, _ref1; - _ref = [['Unread Count', Unread, Conf['Unread Count']], ['Quote Threading', QuoteThreading, Conf['Quote Threading'] && !Conf['Unread Count']]]; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - _ref1 = _ref[_i], name = _ref1[0], feature = _ref1[1], condition = _ref1[2]; - try { - if (condition) { - feature.ready(); - } - } catch (_error) { - err = _error; - if (!errors) { - errors = []; - } - errors.push({ - message: "Failed to reconnect feature " + name + ".", - error: err - }); + ready: function(name, feature, condition) { + var err, error; + try { + if (condition) { + feature(); } + } catch (_error) { + err = _error; + error = [ + { + message: "Quote Threading Failed.", + error: err + } + ]; } - if (errors) { - Main.handleErrors(errors); + if (error) { + Main.handleErrors(error); } return QR.generatePostableThreadsList(); }, @@ -12159,7 +12154,7 @@ } Main.callbackNodes(Thread, [thread]); Main.callbackNodes(Post, posts); - Navigate.ready(); + Navigate.ready('Quote Threading', QuoteThreading.force, Conf['Quote Threading']); return Navigate.buildThread(); }, buildThread: function() { @@ -12168,6 +12163,7 @@ $.rmAll(board); $.add(board, Navigate.threadRoot); if (Conf['Unread Count']) { + Navigate.ready('Unread Count', Unread.ready, Conf['Unread Count']); Unread.read(); return Unread.update(); } @@ -12182,18 +12178,6 @@ }); return Navigate.navigate.call(a); }); - }, - refresh: function(context) { - var boardID, feature, name, threadID, view, _i, _len, _ref, _ref1; - return; - boardID = context.boardID, view = context.view, threadID = context.threadID; - _ref = Main.features; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - _ref1 = _ref[_i], name = _ref1[0], feature = _ref1[1]; - if (feature.refresh) { - feature.refresh(); - } - } } }; diff --git a/src/General/Navigate.coffee b/src/General/Navigate.coffee index 8dc95b6a8..0000c5d7b 100644 --- a/src/General/Navigate.coffee +++ b/src/General/Navigate.coffee @@ -81,20 +81,16 @@ Navigate = return - ready: -> - for [name, feature, condition] in [ - ['Unread Count', Unread, Conf['Unread Count']] - ['Quote Threading', QuoteThreading, Conf['Quote Threading'] and not Conf['Unread Count']] - ] - try - feature.ready() if condition - catch err - errors = [] unless errors - errors.push - message: "Failed to reconnect feature #{name}." - error: err + ready: (name, feature, condition) -> + try + feature() if condition + catch err + error = [ + message: "Quote Threading Failed." + error: err + ] - Main.handleErrors errors if errors + Main.handleErrors error if error QR.generatePostableThreadsList() updateContext: (view) -> @@ -220,8 +216,6 @@ Navigate = Navigate.notice = new Notice 'info', 'Loading thread...' ), 3 * $.SECOND - # Navigate.refresh {boardID, view, threadID} - load: (e) -> $.rmClass Index.button, 'fa-spin' {req, notice} = Navigate @@ -278,7 +272,7 @@ Navigate = Main.callbackNodes Thread, [thread] Main.callbackNodes Post, posts - Navigate.ready() + Navigate.ready 'Quote Threading', QuoteThreading.force, Conf['Quote Threading'] Navigate.buildThread() @@ -286,7 +280,9 @@ Navigate = board = $ '.board' $.rmAll board $.add board, Navigate.threadRoot + if Conf['Unread Count'] + Navigate.ready 'Unread Count', Unread.ready, Conf['Unread Count'] Unread.read() Unread.update() @@ -300,11 +296,3 @@ Navigate = id: 'popState' Navigate.navigate.call a - - refresh: (context) -> - return - {boardID, view, threadID} = context - - # Refresh features - feature.refresh() for [name, feature] in Main.features when feature.refresh - return