ThreadStats.disconnect()
This commit is contained in:
parent
ab8607710b
commit
84cbff8a77
@ -8680,6 +8680,24 @@
|
|||||||
ThreadStats.update(postCount, fileCount);
|
ThreadStats.update(postCount, fileCount);
|
||||||
return $.on(d, 'ThreadUpdate', ThreadStats.onUpdate);
|
return $.on(d, 'ThreadUpdate', ThreadStats.onUpdate);
|
||||||
},
|
},
|
||||||
|
disconnect: function() {
|
||||||
|
if (!Conf['Thread Stats']) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Conf['Updater and Stats in Header']) {
|
||||||
|
Header.rmShortcut(this.dialog);
|
||||||
|
} else {
|
||||||
|
$.rm(d.body, sc);
|
||||||
|
}
|
||||||
|
clearTimeout(this.timeout);
|
||||||
|
delete this.timeout;
|
||||||
|
delete this.thread;
|
||||||
|
delete this.postCountEl;
|
||||||
|
delete this.fileCountEl;
|
||||||
|
delete this.pageCountEl;
|
||||||
|
Thread.callbacks.rm('Thread Stats');
|
||||||
|
return $.off(d, 'ThreadUpdate', ThreadStats.onUpdate);
|
||||||
|
},
|
||||||
onUpdate: function(e) {
|
onUpdate: function(e) {
|
||||||
var fileCount, postCount, _ref;
|
var fileCount, postCount, _ref;
|
||||||
if (e.detail[404]) {
|
if (e.detail[404]) {
|
||||||
@ -8705,7 +8723,7 @@
|
|||||||
$.addClass(ThreadStats.pageCountEl, 'warning');
|
$.addClass(ThreadStats.pageCountEl, 'warning');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setTimeout(ThreadStats.fetchPage, 2 * $.MINUTE);
|
ThreadStats.timeout = setTimeout(ThreadStats.fetchPage, 2 * $.MINUTE);
|
||||||
return $.ajax("//a.4cdn.org/" + ThreadStats.thread.board + "/threads.json", {
|
return $.ajax("//a.4cdn.org/" + ThreadStats.thread.board + "/threads.json", {
|
||||||
onload: ThreadStats.onThreadsLoad
|
onload: ThreadStats.onThreadsLoad
|
||||||
}, {
|
}, {
|
||||||
@ -8723,11 +8741,12 @@
|
|||||||
_ref = page.threads;
|
_ref = page.threads;
|
||||||
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
|
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
|
||||||
thread = _ref[_j];
|
thread = _ref[_j];
|
||||||
if (thread.no === ThreadStats.thread.ID) {
|
if (!(thread.no === ThreadStats.thread.ID)) {
|
||||||
ThreadStats.pageCountEl.textContent = page.page;
|
continue;
|
||||||
(page.page === pages.length - 1 ? $.addClass : $.rmClass)(ThreadStats.pageCountEl, 'warning');
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
ThreadStats.pageCountEl.textContent = page.page;
|
||||||
|
(page.page === pages.length - 1 ? $.addClass : $.rmClass)(ThreadStats.pageCountEl, 'warning');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -12745,7 +12764,7 @@
|
|||||||
disconnect: function() {
|
disconnect: function() {
|
||||||
var err, errors, feature, features, name, _i, _len, _ref;
|
var err, errors, feature, features, name, _i, _len, _ref;
|
||||||
if (g.VIEW === 'thread') {
|
if (g.VIEW === 'thread') {
|
||||||
features = [['Thread Updater', ThreadUpdater], ['Unread Count', Unread], ['Quote Threading', QuoteThreading]];
|
features = [['Thread Updater', ThreadUpdater], ['Unread Count', Unread], ['Quote Threading', QuoteThreading], ['Thread Stats', ThreadStats]];
|
||||||
}
|
}
|
||||||
for (_i = 0, _len = features.length; _i < _len; _i++) {
|
for (_i = 0, _len = features.length; _i < _len; _i++) {
|
||||||
_ref = features[_i], name = _ref[0], feature = _ref[1];
|
_ref = features[_i], name = _ref[0], feature = _ref[1];
|
||||||
|
|||||||
@ -8663,6 +8663,24 @@
|
|||||||
ThreadStats.update(postCount, fileCount);
|
ThreadStats.update(postCount, fileCount);
|
||||||
return $.on(d, 'ThreadUpdate', ThreadStats.onUpdate);
|
return $.on(d, 'ThreadUpdate', ThreadStats.onUpdate);
|
||||||
},
|
},
|
||||||
|
disconnect: function() {
|
||||||
|
if (!Conf['Thread Stats']) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Conf['Updater and Stats in Header']) {
|
||||||
|
Header.rmShortcut(this.dialog);
|
||||||
|
} else {
|
||||||
|
$.rm(d.body, sc);
|
||||||
|
}
|
||||||
|
clearTimeout(this.timeout);
|
||||||
|
delete this.timeout;
|
||||||
|
delete this.thread;
|
||||||
|
delete this.postCountEl;
|
||||||
|
delete this.fileCountEl;
|
||||||
|
delete this.pageCountEl;
|
||||||
|
Thread.callbacks.rm('Thread Stats');
|
||||||
|
return $.off(d, 'ThreadUpdate', ThreadStats.onUpdate);
|
||||||
|
},
|
||||||
onUpdate: function(e) {
|
onUpdate: function(e) {
|
||||||
var fileCount, postCount, _ref;
|
var fileCount, postCount, _ref;
|
||||||
if (e.detail[404]) {
|
if (e.detail[404]) {
|
||||||
@ -8688,7 +8706,7 @@
|
|||||||
$.addClass(ThreadStats.pageCountEl, 'warning');
|
$.addClass(ThreadStats.pageCountEl, 'warning');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setTimeout(ThreadStats.fetchPage, 2 * $.MINUTE);
|
ThreadStats.timeout = setTimeout(ThreadStats.fetchPage, 2 * $.MINUTE);
|
||||||
return $.ajax("//a.4cdn.org/" + ThreadStats.thread.board + "/threads.json", {
|
return $.ajax("//a.4cdn.org/" + ThreadStats.thread.board + "/threads.json", {
|
||||||
onload: ThreadStats.onThreadsLoad
|
onload: ThreadStats.onThreadsLoad
|
||||||
}, {
|
}, {
|
||||||
@ -8706,11 +8724,12 @@
|
|||||||
_ref = page.threads;
|
_ref = page.threads;
|
||||||
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
|
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
|
||||||
thread = _ref[_j];
|
thread = _ref[_j];
|
||||||
if (thread.no === ThreadStats.thread.ID) {
|
if (!(thread.no === ThreadStats.thread.ID)) {
|
||||||
ThreadStats.pageCountEl.textContent = page.page;
|
continue;
|
||||||
(page.page === pages.length - 1 ? $.addClass : $.rmClass)(ThreadStats.pageCountEl, 'warning');
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
ThreadStats.pageCountEl.textContent = page.page;
|
||||||
|
(page.page === pages.length - 1 ? $.addClass : $.rmClass)(ThreadStats.pageCountEl, 'warning');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -12722,7 +12741,7 @@
|
|||||||
disconnect: function() {
|
disconnect: function() {
|
||||||
var err, errors, feature, features, name, _i, _len, _ref;
|
var err, errors, feature, features, name, _i, _len, _ref;
|
||||||
if (g.VIEW === 'thread') {
|
if (g.VIEW === 'thread') {
|
||||||
features = [['Thread Updater', ThreadUpdater], ['Unread Count', Unread], ['Quote Threading', QuoteThreading]];
|
features = [['Thread Updater', ThreadUpdater], ['Unread Count', Unread], ['Quote Threading', QuoteThreading], ['Thread Stats', ThreadStats]];
|
||||||
}
|
}
|
||||||
for (_i = 0, _len = features.length; _i < _len; _i++) {
|
for (_i = 0, _len = features.length; _i < _len; _i++) {
|
||||||
_ref = features[_i], name = _ref[0], feature = _ref[1];
|
_ref = features[_i], name = _ref[0], feature = _ref[1];
|
||||||
|
|||||||
@ -341,6 +341,7 @@ Main =
|
|||||||
['Thread Updater', ThreadUpdater]
|
['Thread Updater', ThreadUpdater]
|
||||||
['Unread Count', Unread]
|
['Unread Count', Unread]
|
||||||
['Quote Threading', QuoteThreading]
|
['Quote Threading', QuoteThreading]
|
||||||
|
['Thread Stats', ThreadStats]
|
||||||
]
|
]
|
||||||
|
|
||||||
for [name, feature] in features
|
for [name, feature] in features
|
||||||
|
|||||||
@ -34,6 +34,25 @@ ThreadStats =
|
|||||||
ThreadStats.update postCount, fileCount
|
ThreadStats.update postCount, fileCount
|
||||||
$.on d, 'ThreadUpdate', ThreadStats.onUpdate
|
$.on d, 'ThreadUpdate', ThreadStats.onUpdate
|
||||||
|
|
||||||
|
disconnect: ->
|
||||||
|
return unless Conf['Thread Stats']
|
||||||
|
|
||||||
|
if Conf['Updater and Stats in Header']
|
||||||
|
Header.rmShortcut @dialog
|
||||||
|
else
|
||||||
|
$.rm d.body, sc
|
||||||
|
|
||||||
|
clearTimeout @timeout # a possible race condition might be that this won't clear in time, but the resulting error will prevent issues anyways.
|
||||||
|
|
||||||
|
delete @timeout
|
||||||
|
delete @thread
|
||||||
|
delete @postCountEl
|
||||||
|
delete @fileCountEl
|
||||||
|
delete @pageCountEl
|
||||||
|
|
||||||
|
Thread.callbacks.rm 'Thread Stats'
|
||||||
|
$.off d, 'ThreadUpdate', ThreadStats.onUpdate
|
||||||
|
|
||||||
onUpdate: (e) ->
|
onUpdate: (e) ->
|
||||||
return if e.detail[404]
|
return if e.detail[404]
|
||||||
{postCount, fileCount} = e.detail
|
{postCount, fileCount} = e.detail
|
||||||
@ -52,7 +71,7 @@ ThreadStats =
|
|||||||
ThreadStats.pageCountEl.textContent = 'Dead'
|
ThreadStats.pageCountEl.textContent = 'Dead'
|
||||||
$.addClass ThreadStats.pageCountEl, 'warning'
|
$.addClass ThreadStats.pageCountEl, 'warning'
|
||||||
return
|
return
|
||||||
setTimeout ThreadStats.fetchPage, 2 * $.MINUTE
|
ThreadStats.timeout = setTimeout ThreadStats.fetchPage, 2 * $.MINUTE
|
||||||
$.ajax "//a.4cdn.org/#{ThreadStats.thread.board}/threads.json", onload: ThreadStats.onThreadsLoad,
|
$.ajax "//a.4cdn.org/#{ThreadStats.thread.board}/threads.json", onload: ThreadStats.onThreadsLoad,
|
||||||
whenModified: true
|
whenModified: true
|
||||||
|
|
||||||
@ -60,8 +79,7 @@ ThreadStats =
|
|||||||
return unless Conf["Page Count in Stats"] and @status is 200
|
return unless Conf["Page Count in Stats"] and @status is 200
|
||||||
pages = JSON.parse @response
|
pages = JSON.parse @response
|
||||||
for page in pages
|
for page in pages
|
||||||
for thread in page.threads
|
for thread in page.threads when thread.no is ThreadStats.thread.ID
|
||||||
if thread.no is ThreadStats.thread.ID
|
ThreadStats.pageCountEl.textContent = page.page
|
||||||
ThreadStats.pageCountEl.textContent = page.page
|
(if page.page is pages.length - 1 then $.addClass else $.rmClass) ThreadStats.pageCountEl, 'warning'
|
||||||
(if page.page is pages.length - 1 then $.addClass else $.rmClass) ThreadStats.pageCountEl, 'warning'
|
return
|
||||||
return
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user