diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index ad0c83c0a..c4d8ef112 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -746,6 +746,10 @@ }; })(); + $.desync = function(key) { + return delete $.syncing[g.NAMESPACE + key]; + }; + $["delete"] = function(keys) { var key, _i, _len; if (!(keys instanceof Array)) { @@ -1458,6 +1462,19 @@ return typeof this.sync === "function" ? this.sync() : void 0; }; + DataBoard.prototype.disconnect = function() { + var key, _i, _len, _results; + $.desync(this.key); + _results = []; + for (_i = 0, _len = this.length; _i < _len; _i++) { + key = this[_i]; + if (this.hasOwnKey(key)) { + _results.push(delete this[key]); + } + } + return _results; + }; + return DataBoard; })(); @@ -9542,6 +9559,9 @@ if (g.VIEW !== 'thread' || !Conf['Unread Count'] && !Conf['Unread Favicon'] && !Conf['Desktop Notifications']) { return; } + return Unread.connect(); + }, + connect: function() { this.db = new DataBoard('lastReadPosts', this.sync); this.hr = $.el('hr', { id: 'unread-line' @@ -9553,6 +9573,28 @@ cb: this.node }); }, + disconnect: function() { + var hr, name, parent, _i, _len, _ref; + if (!Unread.db) { + return; + } + Unread.db.disconnect(); + if (parent = (hr = Unread.hr).parentElement) { + $.rm(hr, parent); + } + _ref = ['db', 'hr', 'posts', 'postsQuotingYou', 'thread', 'title', 'lastReadPost']; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + name = _ref[_i]; + delete Unread[name]; + } + $.off(d, '4chanXInitFinished', Unread.ready); + $.off(d, 'ThreadUpdate', Unread.onUpdate); + $.off(d, 'scroll visibilitychange', Unread.read); + if (Conf['Unread Line']) { + $.off(d, 'visibilitychange', Unread.setLine); + } + return Thread.callbacks.rm('Unread'); + }, node: function() { Unread.thread = this; Unread.title = d.title; diff --git a/builds/crx/script.js b/builds/crx/script.js index e237cabbd..aa2390958 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -727,6 +727,10 @@ }; })(); + $.desync = function(key) { + return delete $.syncing[key]; + }; + $.localKeys = ['name', 'uniqueID', 'tripcode', 'capcode', 'email', 'subject', 'comment', 'flag', 'filename', 'dimensions', 'filesize', 'MD5', 'usercss']; $["delete"] = function(keys) { @@ -1464,6 +1468,19 @@ return typeof this.sync === "function" ? this.sync() : void 0; }; + DataBoard.prototype.disconnect = function() { + var key, _i, _len, _results; + $.desync(this.key); + _results = []; + for (_i = 0, _len = this.length; _i < _len; _i++) { + key = this[_i]; + if (this.hasOwnKey(key)) { + _results.push(delete this[key]); + } + } + return _results; + }; + return DataBoard; })(); @@ -9525,6 +9542,9 @@ if (g.VIEW !== 'thread' || !Conf['Unread Count'] && !Conf['Unread Favicon'] && !Conf['Desktop Notifications']) { return; } + return Unread.connect(); + }, + connect: function() { this.db = new DataBoard('lastReadPosts', this.sync); this.hr = $.el('hr', { id: 'unread-line' @@ -9536,6 +9556,28 @@ cb: this.node }); }, + disconnect: function() { + var hr, name, parent, _i, _len, _ref; + if (!Unread.db) { + return; + } + Unread.db.disconnect(); + if (parent = (hr = Unread.hr).parentElement) { + $.rm(hr, parent); + } + _ref = ['db', 'hr', 'posts', 'postsQuotingYou', 'thread', 'title', 'lastReadPost']; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + name = _ref[_i]; + delete Unread[name]; + } + $.off(d, '4chanXInitFinished', Unread.ready); + $.off(d, 'ThreadUpdate', Unread.onUpdate); + $.off(d, 'scroll visibilitychange', Unread.read); + if (Conf['Unread Line']) { + $.off(d, 'visibilitychange', Unread.setLine); + } + return Thread.callbacks.rm('Unread'); + }, node: function() { Unread.thread = this; Unread.title = d.title; diff --git a/src/General/lib/$.coffee b/src/General/lib/$.coffee index d91010ae8..87807ac9c 100755 --- a/src/General/lib/$.coffee +++ b/src/General/lib/$.coffee @@ -268,6 +268,7 @@ $.item = (key, val) -> item $.syncing = {} + <% if (type === 'crx') { %> $.sync = do -> chrome.storage.onChanged.addListener (changes) -> @@ -277,6 +278,8 @@ $.sync = do -> return (key, cb) -> $.syncing[key] = cb +$.desync = (key) -> delete $.syncing[key] + $.localKeys = [ # filters 'name', @@ -361,6 +364,8 @@ $.sync = do -> cb JSON.parse(newValue), key (key, cb) -> $.syncing[g.NAMESPACE + key] = cb +$.desync = (key) -> delete $.syncing[g.NAMESPACE + key] + $.delete = (keys) -> unless keys instanceof Array keys = [keys] diff --git a/src/General/lib/databoard.class b/src/General/lib/databoard.class index 1dc37e235..9318ff542 100755 --- a/src/General/lib/databoard.class +++ b/src/General/lib/databoard.class @@ -90,3 +90,7 @@ class DataBoard onSync: (data) => @data = data or boards: {} @sync?() + + disconnect: -> + $.desync @key + delete @[key] for key in @ when @hasOwnKey key \ No newline at end of file diff --git a/src/Monitoring/Unread.coffee b/src/Monitoring/Unread.coffee index 059fa2dc6..11917d255 100755 --- a/src/Monitoring/Unread.coffee +++ b/src/Monitoring/Unread.coffee @@ -2,6 +2,9 @@ Unread = init: -> return if g.VIEW isnt 'thread' or !Conf['Unread Count'] and !Conf['Unread Favicon'] and !Conf['Desktop Notifications'] + Unread.connect() + + connect: -> @db = new DataBoard 'lastReadPosts', @sync @hr = $.el 'hr', id: 'unread-line' @@ -12,6 +15,21 @@ Unread = name: 'Unread' cb: @node + disconnect: -> + return unless Unread.db + + Unread.db.disconnect() + $.rm hr, parent if parent = (hr = Unread.hr).parentElement + + delete Unread[name] for name in ['db', 'hr', 'posts', 'postsQuotingYou', 'thread', 'title', 'lastReadPost'] + + $.off d, '4chanXInitFinished', Unread.ready + $.off d, 'ThreadUpdate', Unread.onUpdate + $.off d, 'scroll visibilitychange', Unread.read + $.off d, 'visibilitychange', Unread.setLine if Conf['Unread Line'] + + Thread.callbacks.rm 'Unread' + node: -> Unread.thread = @ Unread.title = d.title