From 3d87a9cfb67191755df059629f7f755c91a10043 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sat, 4 Jan 2014 15:34:17 -0700 Subject: [PATCH 1/2] Gonna revert this for now, was causing weird issues. --- LICENSE | 8 +++---- builds/4chan-X.user.js | 8 +++---- builds/crx/script.js | 51 ++++++++++++++-------------------------- src/General/lib/$.coffee | 36 ++++++++++------------------ 4 files changed, 39 insertions(+), 64 deletions(-) diff --git a/LICENSE b/LICENSE index 38ffc24ad..5ea10f543 100755 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ /* -* 4chan X - Version 1.2.44 - 2013-12-27 +* 4chan X - Version 1.2.44 - 2014-01-04 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE @@ -8,11 +8,11 @@ * http://zixaphir.github.io/appchan-x/ * 4chan x Copyright © 2009-2011 James Campos * https://github.com/aeosynth/4chan-x -* 4chan x Copyright © 2012-2013 Nicolas Stepien +* 4chan x Copyright © 2012-2014 Nicolas Stepien * https://4chan-x.just-believe.in/ -* 4chan x Copyright © 2013-2013 Jordan Bates +* 4chan x Copyright © 2013-2014 Jordan Bates * http://seaweedchan.github.io/4chan-x/ -* 4chan x Copyright © 2012-2013 ihavenoface +* 4chan x Copyright © 2012-2014 ihavenoface * http://ihavenoface.github.io/4chan-x/ * 4chan SS Copyright © 2011-2013 Ahodesuka * https://github.com/ahodesuka/4chan-Style-Script/ diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 01a734513..d354f9c5d 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -22,7 +22,7 @@ // ==/UserScript== /* -* 4chan X - Version 1.2.44 - 2013-12-27 +* 4chan X - Version 1.2.44 - 2014-01-04 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE @@ -31,11 +31,11 @@ * http://zixaphir.github.io/appchan-x/ * 4chan x Copyright © 2009-2011 James Campos * https://github.com/aeosynth/4chan-x -* 4chan x Copyright © 2012-2013 Nicolas Stepien +* 4chan x Copyright © 2012-2014 Nicolas Stepien * https://4chan-x.just-believe.in/ -* 4chan x Copyright © 2013-2013 Jordan Bates +* 4chan x Copyright © 2013-2014 Jordan Bates * http://seaweedchan.github.io/4chan-x/ -* 4chan x Copyright © 2012-2013 ihavenoface +* 4chan x Copyright © 2012-2014 ihavenoface * http://ihavenoface.github.io/4chan-x/ * 4chan SS Copyright © 2011-2013 Ahodesuka * https://github.com/ahodesuka/4chan-Style-Script/ diff --git a/builds/crx/script.js b/builds/crx/script.js index dac844bf7..50149405a 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript /* -* 4chan X - Version 1.2.44 - 2013-12-27 +* 4chan X - Version 1.2.44 - 2014-01-04 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE @@ -9,11 +9,11 @@ * http://zixaphir.github.io/appchan-x/ * 4chan x Copyright © 2009-2011 James Campos * https://github.com/aeosynth/4chan-x -* 4chan x Copyright © 2012-2013 Nicolas Stepien +* 4chan x Copyright © 2012-2014 Nicolas Stepien * https://4chan-x.just-believe.in/ -* 4chan x Copyright © 2013-2013 Jordan Bates +* 4chan x Copyright © 2013-2014 Jordan Bates * http://seaweedchan.github.io/4chan-x/ -* 4chan x Copyright © 2012-2013 ihavenoface +* 4chan x Copyright © 2012-2014 ihavenoface * http://ihavenoface.github.io/4chan-x/ * 4chan SS Copyright © 2011-2013 Ahodesuka * https://github.com/ahodesuka/4chan-Style-Script/ @@ -772,39 +772,24 @@ }; $.set = (function() { - var items, setAll, setArea, timeout; - items = { - sync: {}, - local: {} - }; - timeout = {}; - setArea = function(area) { - if (timeout[area]) { - return; - } - return chrome.storage[area].set(items[area], function() { - if (chrome.runtime.lastError) { - c.error(chrome.runtime.lastError.message); - timeout[area] = setTimeout(setArea, $.MINUTE, area); - return; - } - items[area] = {}; - return delete timeout[area]; - }); - }; - setAll = $.debounce($.SECOND, function() { + var items, localItems, set; + items = {}; + localItems = {}; + set = $.debounce($.SECOND, function() { var err, key, _i, _len, _ref; _ref = $.localKeys; for (_i = 0, _len = _ref.length; _i < _len; _i++) { key = _ref[_i]; - if (key in items.sync) { - items.local[key] = items.sync[key]; - delete items.sync[key]; + if (key in items) { + (localItems || (localItems = {}))[key] = items[key]; + delete items[key]; } } try { - setArea('local'); - return setArea('sync'); + chrome.storage.local.set(localItems); + chrome.storage.sync.set(items); + items = {}; + return localItems = {}; } catch (_error) { err = _error; return c.error(err.stack); @@ -812,11 +797,11 @@ }); return function(key, val) { if (typeof key === 'string') { - items.sync[key] = val; + items[key] = val; } else { - $.extend(items.sync, key); + $.extend(items, key); } - return setAll(); + return set(); }; })(); diff --git a/src/General/lib/$.coffee b/src/General/lib/$.coffee index a5e58ba1d..d91010ae8 100755 --- a/src/General/lib/$.coffee +++ b/src/General/lib/$.coffee @@ -329,38 +329,28 @@ $.get = (key, val, cb) -> chrome.storage.sync.get syncItems, done $.set = do -> - items = - sync: {} - local: {} - timeout = {} + items = {} + localItems = {} - setArea = (area) -> - return if timeout[area] - chrome.storage[area].set items[area], -> - if chrome.runtime.lastError - c.error chrome.runtime.lastError.message - timeout[area] = setTimeout setArea, $.MINUTE, area - return - items[area] = {} - delete timeout[area] - - setAll = $.debounce $.SECOND, -> + set = $.debounce $.SECOND, -> for key in $.localKeys - if key of items.sync - items.local[key] = items.sync[key] - delete items.sync[key] + if key of items + (localItems or= {})[key] = items[key] + delete items[key] try - setArea 'local' - setArea 'sync' + chrome.storage.local.set localItems + chrome.storage.sync.set items + items = {} + localItems = {} catch err c.error err.stack (key, val) -> if typeof key is 'string' - items.sync[key] = val + items[key] = val else - $.extend items.sync, key - setAll() + $.extend items, key + set() <% } else { %> From c979f440282c8bb9837cb17601e716c4c78291fc Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sat, 4 Jan 2014 19:51:28 -0700 Subject: [PATCH 2/2] As far as I can tell, this wasn't working at all. --- builds/4chan-X.user.js | 8 +++----- builds/crx/script.js | 8 +++----- src/Monitoring/Unread.coffee | 8 +++----- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index d354f9c5d..9aa9aa4c3 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -9451,11 +9451,9 @@ posts = Object.keys(Unread.thread.posts); root = Unread.thread.posts[posts[posts.length - 1]].nodes.root; } - return $.on(window, 'load', function() { - if (Header.getBottomOf(root) < 0) { - return Header.scrollTo(root, down); - } - }); + if (Header.getBottomOf(root) < 0) { + return Header.scrollTo(root, down); + } }, sync: function() { var lastReadPost; diff --git a/builds/crx/script.js b/builds/crx/script.js index 50149405a..5066a03c1 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -9434,11 +9434,9 @@ posts = Object.keys(Unread.thread.posts); root = Unread.thread.posts[posts[posts.length - 1]].nodes.root; } - return $.on(window, 'load', function() { - if (Header.getBottomOf(root) < 0) { - return Header.scrollTo(root, down); - } - }); + if (Header.getBottomOf(root) < 0) { + return Header.scrollTo(root, down); + } }, sync: function() { var lastReadPost; diff --git a/src/Monitoring/Unread.coffee b/src/Monitoring/Unread.coffee index 36d5f5213..385383639 100755 --- a/src/Monitoring/Unread.coffee +++ b/src/Monitoring/Unread.coffee @@ -46,11 +46,9 @@ Unread = # Scroll to the last read post. posts = Object.keys Unread.thread.posts {root} = Unread.thread.posts[posts[posts.length - 1]].nodes - # Prevent the browser to scroll back to - # the previous scroll location on page load. - $.on window, 'load', -> - # Scroll to the target unless we scrolled past it. - Header.scrollTo root, down if Header.getBottomOf(root) < 0 + + # Scroll to the target unless we scrolled past it. + Header.scrollTo root, down if Header.getBottomOf(root) < 0 sync: -> lastReadPost = Unread.db.get