ThreadStats.disconnect()
This commit is contained in:
parent
ab8607710b
commit
84cbff8a77
@ -8680,6 +8680,24 @@
|
||||
ThreadStats.update(postCount, fileCount);
|
||||
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) {
|
||||
var fileCount, postCount, _ref;
|
||||
if (e.detail[404]) {
|
||||
@ -8705,7 +8723,7 @@
|
||||
$.addClass(ThreadStats.pageCountEl, 'warning');
|
||||
return;
|
||||
}
|
||||
setTimeout(ThreadStats.fetchPage, 2 * $.MINUTE);
|
||||
ThreadStats.timeout = setTimeout(ThreadStats.fetchPage, 2 * $.MINUTE);
|
||||
return $.ajax("//a.4cdn.org/" + ThreadStats.thread.board + "/threads.json", {
|
||||
onload: ThreadStats.onThreadsLoad
|
||||
}, {
|
||||
@ -8723,11 +8741,12 @@
|
||||
_ref = page.threads;
|
||||
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
|
||||
thread = _ref[_j];
|
||||
if (thread.no === ThreadStats.thread.ID) {
|
||||
ThreadStats.pageCountEl.textContent = page.page;
|
||||
(page.page === pages.length - 1 ? $.addClass : $.rmClass)(ThreadStats.pageCountEl, 'warning');
|
||||
return;
|
||||
if (!(thread.no === ThreadStats.thread.ID)) {
|
||||
continue;
|
||||
}
|
||||
ThreadStats.pageCountEl.textContent = page.page;
|
||||
(page.page === pages.length - 1 ? $.addClass : $.rmClass)(ThreadStats.pageCountEl, 'warning');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -12745,7 +12764,7 @@
|
||||
disconnect: function() {
|
||||
var err, errors, feature, features, name, _i, _len, _ref;
|
||||
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++) {
|
||||
_ref = features[_i], name = _ref[0], feature = _ref[1];
|
||||
|
||||
@ -8663,6 +8663,24 @@
|
||||
ThreadStats.update(postCount, fileCount);
|
||||
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) {
|
||||
var fileCount, postCount, _ref;
|
||||
if (e.detail[404]) {
|
||||
@ -8688,7 +8706,7 @@
|
||||
$.addClass(ThreadStats.pageCountEl, 'warning');
|
||||
return;
|
||||
}
|
||||
setTimeout(ThreadStats.fetchPage, 2 * $.MINUTE);
|
||||
ThreadStats.timeout = setTimeout(ThreadStats.fetchPage, 2 * $.MINUTE);
|
||||
return $.ajax("//a.4cdn.org/" + ThreadStats.thread.board + "/threads.json", {
|
||||
onload: ThreadStats.onThreadsLoad
|
||||
}, {
|
||||
@ -8706,11 +8724,12 @@
|
||||
_ref = page.threads;
|
||||
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
|
||||
thread = _ref[_j];
|
||||
if (thread.no === ThreadStats.thread.ID) {
|
||||
ThreadStats.pageCountEl.textContent = page.page;
|
||||
(page.page === pages.length - 1 ? $.addClass : $.rmClass)(ThreadStats.pageCountEl, 'warning');
|
||||
return;
|
||||
if (!(thread.no === ThreadStats.thread.ID)) {
|
||||
continue;
|
||||
}
|
||||
ThreadStats.pageCountEl.textContent = page.page;
|
||||
(page.page === pages.length - 1 ? $.addClass : $.rmClass)(ThreadStats.pageCountEl, 'warning');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -12722,7 +12741,7 @@
|
||||
disconnect: function() {
|
||||
var err, errors, feature, features, name, _i, _len, _ref;
|
||||
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++) {
|
||||
_ref = features[_i], name = _ref[0], feature = _ref[1];
|
||||
|
||||
@ -341,6 +341,7 @@ Main =
|
||||
['Thread Updater', ThreadUpdater]
|
||||
['Unread Count', Unread]
|
||||
['Quote Threading', QuoteThreading]
|
||||
['Thread Stats', ThreadStats]
|
||||
]
|
||||
|
||||
for [name, feature] in features
|
||||
|
||||
@ -9,11 +9,11 @@ ThreadStats =
|
||||
title: 'Post Count / File Count' + (if Conf["Page Count in Stats"] then " / Page Count" else "")
|
||||
$.ready ->
|
||||
Header.addShortcut sc
|
||||
else
|
||||
else
|
||||
@dialog = sc = UI.dialog 'thread-stats', 'bottom: 0px; right: 0px;',
|
||||
"<div class=move title='Post Count / File Count#{if Conf["Page Count in Stats"] then " / Page Count" else ""}'><span id=post-count>0</span> / <span id=file-count>0</span>#{if Conf["Page Count in Stats"] then " / <span id=page-count>0</span>" else ""}</div>"
|
||||
$.ready =>
|
||||
$.add d.body, sc
|
||||
$.ready =>
|
||||
$.add d.body, sc
|
||||
|
||||
@postCountEl = $ '#post-count', sc
|
||||
@fileCountEl = $ '#file-count', sc
|
||||
@ -34,6 +34,25 @@ ThreadStats =
|
||||
ThreadStats.update postCount, fileCount
|
||||
$.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) ->
|
||||
return if e.detail[404]
|
||||
{postCount, fileCount} = e.detail
|
||||
@ -48,11 +67,11 @@ ThreadStats =
|
||||
|
||||
fetchPage: ->
|
||||
return if !Conf["Page Count in Stats"]
|
||||
if ThreadStats.thread.isDead
|
||||
if ThreadStats.thread.isDead
|
||||
ThreadStats.pageCountEl.textContent = 'Dead'
|
||||
$.addClass ThreadStats.pageCountEl, 'warning'
|
||||
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,
|
||||
whenModified: true
|
||||
|
||||
@ -60,8 +79,7 @@ ThreadStats =
|
||||
return unless Conf["Page Count in Stats"] and @status is 200
|
||||
pages = JSON.parse @response
|
||||
for page in pages
|
||||
for thread in page.threads
|
||||
if thread.no is ThreadStats.thread.ID
|
||||
ThreadStats.pageCountEl.textContent = page.page
|
||||
(if page.page is pages.length - 1 then $.addClass else $.rmClass) ThreadStats.pageCountEl, 'warning'
|
||||
return
|
||||
for thread in page.threads when thread.no is ThreadStats.thread.ID
|
||||
ThreadStats.pageCountEl.textContent = page.page
|
||||
(if page.page is pages.length - 1 then $.addClass else $.rmClass) ThreadStats.pageCountEl, 'warning'
|
||||
return
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user