Unread.disconnect()
This commit is contained in:
parent
5fe3f55414
commit
32641549f2
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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]
|
||||
|
||||
@ -90,3 +90,7 @@ class DataBoard
|
||||
onSync: (data) =>
|
||||
@data = data or boards: {}
|
||||
@sync?()
|
||||
|
||||
disconnect: ->
|
||||
$.desync @key
|
||||
delete @[key] for key in @ when @hasOwnKey key
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user