Page Count in Stats option, #43

This commit is contained in:
Jordan Bates 2013-05-27 00:25:56 -07:00
parent 646f668c58
commit 55def8c027
6 changed files with 164 additions and 16 deletions

View File

@ -1,5 +1,5 @@
/*
* 4chan X - Version 1.2.10 - 2013-05-25
* 4chan X - Version 1.2.10 - 2013-05-27
*
* Licensed under the MIT license.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE

View File

@ -19,7 +19,7 @@
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAgMAAAAqbBEUAAAACVBMVEUAAGcAAABmzDNZt9VtAAAAAXRSTlMAQObYZgAAAHFJREFUKFOt0LENACEIBdBv4Qju4wgWanEj3D6OcIVMKaitYHEU/jwTCQj8W75kiVCSBvdQ5/AvfVHBin11BgdRq3ysBgfwBDRrj3MCIA+oAQaku/Q1cNctrAmyDl577tOThYt/Y1RBM4DgOHzM0HFTAyLukH/cmRnqAAAAAElFTkSuQmCC
// ==/UserScript==
/*
* 4chan X - Version 1.2.10 - 2013-05-25
* 4chan X - Version 1.2.10 - 2013-05-27
*
* Licensed under the MIT license.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE
@ -182,6 +182,7 @@
'Scroll to Last Read Post': [true, 'Scroll back to the last read post when reopening a thread.'],
'Thread Excerpt': [true, 'Show an excerpt of the thread in the tab title.'],
'Thread Stats': [true, 'Display reply and image count.'],
'Page Count in Stats': [false, 'Display the page count in the thread stats as well.'],
'Updater and Stats in Header': [true, 'Places the thread updater and thread stats in the header instead of floating them.'],
'Thread Watcher': [true, 'Bookmark threads.'],
'Toggleable Thread Watcher': [false, 'Adds a shortcut for the thread watcher, hides the watcher by default, and makes it scroll with the page.'],
@ -6981,20 +6982,23 @@
}
if (Conf['Updater and Stats in Header']) {
this.dialog = sc = $.el('span', {
innerHTML: "<span id=post-count>0</span> / <span id=file-count>0</span>",
id: 'thread-stats'
innerHTML: "<span id=post-count>0</span> / <span id=file-count>0</span>" + (Conf["Page Count in Stats"] ? " / <span id=page-count>0</span>" : ""),
id: 'thread-stats',
title: 'Post Count / File Count' + (Conf["Page Count in Stats"] ? " / Page Count" : "")
});
$.ready(function() {
return Header.addShortcut(sc);
});
} else {
this.dialog = sc = UI.dialog('thread-stats', 'bottom: 0px; right: 0px;', "<div class=move><span id=post-count>0</span> / <span id=file-count>0</span></div>");
this.dialog = sc = UI.dialog('thread-stats', 'bottom: 0px; right: 0px;', "<div class=move title='Post Count / File Count" + (Conf["Page Count in Stats"] ? " / Page Count" : "") + "'><span id=post-count>0</span> / <span id=file-count>0</span>" + (Conf["Page Count in Stats"] ? " / <span id=page-count>0</span>" : "") + "</div>");
$.ready(function() {
return $.add(d.body, sc);
});
}
this.postCountEl = $('#post-count', sc);
this.fileCountEl = $('#file-count', sc);
this.pageCountEl = $('#page-count', sc);
this.lastModified = '0';
return Thread.prototype.callbacks.push({
name: 'Thread Stats',
cb: this.node
@ -7034,6 +7038,43 @@
fileCountEl.textContent = fileCount;
(thread.postLimit && !thread.isSticky ? $.addClass : $.rmClass)(postCountEl, 'warning');
return (thread.fileLimit && !thread.isSticky ? $.addClass : $.rmClass)(fileCountEl, 'warning');
},
fetchPage: function() {
if (ThreadStats.thread.isDead || !Conf["Page Count in Stats"]) {
return;
}
setTimeout(ThreadStats.fetchPage, 2 * $.MINUTE);
return $.ajax("//api.4chan.org/" + ThreadStats.thread.board + "/threads.json", {
onload: ThreadStats.onThreadsLoad
}, {
headers: {
'If-Modified-Since': ThreadStats.lastModified
}
});
},
onThreadsLoad: function() {
var page, pages, thread, _i, _j, _len, _len1, _ref;
if (!Conf["Page Count in Stats"]) {
return;
}
ThreadStats.lastModified = this.getResponseHeader('Last-Modified');
if (this.status !== 200) {
return;
}
pages = JSON.parse(this.response);
for (_i = 0, _len = pages.length; _i < _len; _i++) {
page = pages[_i];
_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;
}
}
}
}
};

View File

@ -19,7 +19,7 @@
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAgMAAAAqbBEUAAAACVBMVEUAAGcAAABmzDNZt9VtAAAAAXRSTlMAQObYZgAAAHFJREFUKFOt0LENACEIBdBv4Qju4wgWanEj3D6OcIVMKaitYHEU/jwTCQj8W75kiVCSBvdQ5/AvfVHBin11BgdRq3ysBgfwBDRrj3MCIA+oAQaku/Q1cNctrAmyDl577tOThYt/Y1RBM4DgOHzM0HFTAyLukH/cmRnqAAAAAElFTkSuQmCC
// ==/UserScript==
/*
* 4chan X - Version 1.2.10 - 2013-05-25
* 4chan X - Version 1.2.10 - 2013-05-27
*
* Licensed under the MIT license.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE
@ -182,6 +182,7 @@
'Scroll to Last Read Post': [true, 'Scroll back to the last read post when reopening a thread.'],
'Thread Excerpt': [true, 'Show an excerpt of the thread in the tab title.'],
'Thread Stats': [true, 'Display reply and image count.'],
'Page Count in Stats': [false, 'Display the page count in the thread stats as well.'],
'Updater and Stats in Header': [true, 'Places the thread updater and thread stats in the header instead of floating them.'],
'Thread Watcher': [true, 'Bookmark threads.'],
'Toggleable Thread Watcher': [false, 'Adds a shortcut for the thread watcher, hides the watcher by default, and makes it scroll with the page.'],
@ -6990,20 +6991,23 @@
}
if (Conf['Updater and Stats in Header']) {
this.dialog = sc = $.el('span', {
innerHTML: "<span id=post-count>0</span> / <span id=file-count>0</span>",
id: 'thread-stats'
innerHTML: "<span id=post-count>0</span> / <span id=file-count>0</span>" + (Conf["Page Count in Stats"] ? " / <span id=page-count>0</span>" : ""),
id: 'thread-stats',
title: 'Post Count / File Count' + (Conf["Page Count in Stats"] ? " / Page Count" : "")
});
$.ready(function() {
return Header.addShortcut(sc);
});
} else {
this.dialog = sc = UI.dialog('thread-stats', 'bottom: 0px; right: 0px;', "<div class=move><span id=post-count>0</span> / <span id=file-count>0</span></div>");
this.dialog = sc = UI.dialog('thread-stats', 'bottom: 0px; right: 0px;', "<div class=move title='Post Count / File Count" + (Conf["Page Count in Stats"] ? " / Page Count" : "") + "'><span id=post-count>0</span> / <span id=file-count>0</span>" + (Conf["Page Count in Stats"] ? " / <span id=page-count>0</span>" : "") + "</div>");
$.ready(function() {
return $.add(d.body, sc);
});
}
this.postCountEl = $('#post-count', sc);
this.fileCountEl = $('#file-count', sc);
this.pageCountEl = $('#page-count', sc);
this.lastModified = '0';
return Thread.prototype.callbacks.push({
name: 'Thread Stats',
cb: this.node
@ -7043,6 +7047,43 @@
fileCountEl.textContent = fileCount;
(thread.postLimit && !thread.isSticky ? $.addClass : $.rmClass)(postCountEl, 'warning');
return (thread.fileLimit && !thread.isSticky ? $.addClass : $.rmClass)(fileCountEl, 'warning');
},
fetchPage: function() {
if (ThreadStats.thread.isDead || !Conf["Page Count in Stats"]) {
return;
}
setTimeout(ThreadStats.fetchPage, 2 * $.MINUTE);
return $.ajax("//api.4chan.org/" + ThreadStats.thread.board + "/threads.json", {
onload: ThreadStats.onThreadsLoad
}, {
headers: {
'If-Modified-Since': ThreadStats.lastModified
}
});
},
onThreadsLoad: function() {
var page, pages, thread, _i, _j, _len, _len1, _ref;
if (!Conf["Page Count in Stats"]) {
return;
}
ThreadStats.lastModified = this.getResponseHeader('Last-Modified');
if (this.status !== 200) {
return;
}
pages = JSON.parse(this.response);
for (_i = 0, _len = pages.length; _i < _len; _i++) {
page = pages[_i];
_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;
}
}
}
}
};

View File

@ -1,6 +1,6 @@
// Generated by CoffeeScript
/*
* 4chan X - Version 1.2.10 - 2013-05-25
* 4chan X - Version 1.2.10 - 2013-05-27
*
* Licensed under the MIT license.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE
@ -164,6 +164,7 @@
'Scroll to Last Read Post': [true, 'Scroll back to the last read post when reopening a thread.'],
'Thread Excerpt': [true, 'Show an excerpt of the thread in the tab title.'],
'Thread Stats': [true, 'Display reply and image count.'],
'Page Count in Stats': [false, 'Display the page count in the thread stats as well.'],
'Updater and Stats in Header': [true, 'Places the thread updater and thread stats in the header instead of floating them.'],
'Thread Watcher': [true, 'Bookmark threads.'],
'Toggleable Thread Watcher': [false, 'Adds a shortcut for the thread watcher, hides the watcher by default, and makes it scroll with the page.'],
@ -6968,20 +6969,23 @@
}
if (Conf['Updater and Stats in Header']) {
this.dialog = sc = $.el('span', {
innerHTML: "<span id=post-count>0</span> / <span id=file-count>0</span>",
id: 'thread-stats'
innerHTML: "<span id=post-count>0</span> / <span id=file-count>0</span>" + (Conf["Page Count in Stats"] ? " / <span id=page-count>0</span>" : ""),
id: 'thread-stats',
title: 'Post Count / File Count' + (Conf["Page Count in Stats"] ? " / Page Count" : "")
});
$.ready(function() {
return Header.addShortcut(sc);
});
} else {
this.dialog = sc = UI.dialog('thread-stats', 'bottom: 0px; right: 0px;', "<div class=move><span id=post-count>0</span> / <span id=file-count>0</span></div>");
this.dialog = sc = UI.dialog('thread-stats', 'bottom: 0px; right: 0px;', "<div class=move title='Post Count / File Count" + (Conf["Page Count in Stats"] ? " / Page Count" : "") + "'><span id=post-count>0</span> / <span id=file-count>0</span>" + (Conf["Page Count in Stats"] ? " / <span id=page-count>0</span>" : "") + "</div>");
$.ready(function() {
return $.add(d.body, sc);
});
}
this.postCountEl = $('#post-count', sc);
this.fileCountEl = $('#file-count', sc);
this.pageCountEl = $('#page-count', sc);
this.lastModified = '0';
return Thread.prototype.callbacks.push({
name: 'Thread Stats',
cb: this.node
@ -7021,6 +7025,43 @@
fileCountEl.textContent = fileCount;
(thread.postLimit && !thread.isSticky ? $.addClass : $.rmClass)(postCountEl, 'warning');
return (thread.fileLimit && !thread.isSticky ? $.addClass : $.rmClass)(fileCountEl, 'warning');
},
fetchPage: function() {
if (ThreadStats.thread.isDead || !Conf["Page Count in Stats"]) {
return;
}
setTimeout(ThreadStats.fetchPage, 2 * $.MINUTE);
return $.ajax("//api.4chan.org/" + ThreadStats.thread.board + "/threads.json", {
onload: ThreadStats.onThreadsLoad
}, {
headers: {
'If-Modified-Since': ThreadStats.lastModified
}
});
},
onThreadsLoad: function() {
var page, pages, thread, _i, _j, _len, _len1, _ref;
if (!Conf["Page Count in Stats"]) {
return;
}
ThreadStats.lastModified = this.getResponseHeader('Last-Modified');
if (this.status !== 200) {
return;
}
pages = JSON.parse(this.response);
for (_i = 0, _len = pages.length; _i < _len; _i++) {
page = pages[_i];
_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;
}
}
}
}
};

View File

@ -229,6 +229,10 @@ Config =
true
'Display reply and image count.'
]
'Page Count in Stats': [
false
'Display the page count in the thread stats as well.'
]
'Updater and Stats in Header': [
true,
'Places the thread updater and thread stats in the header instead of floating them.'

View File

@ -4,18 +4,21 @@ ThreadStats =
if Conf['Updater and Stats in Header']
@dialog = sc = $.el 'span',
innerHTML: "<span id=post-count>0</span> / <span id=file-count>0</span>"
innerHTML: "<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 ""}"
id: 'thread-stats'
title: 'Post Count / File Count' + (if Conf["Page Count in Stats"] then " / Page Count" else "")
$.ready ->
Header.addShortcut sc
else
@dialog = sc = UI.dialog 'thread-stats', 'bottom: 0px; right: 0px;',
"<div class=move><span id=post-count>0</span> / <span id=file-count>0</span></div>"
"<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
@postCountEl = $ '#post-count', sc
@fileCountEl = $ '#file-count', sc
@pageCountEl = $ '#page-count', sc
@lastModified = '0'
Thread::callbacks.push
name: 'Thread Stats'
@ -41,4 +44,22 @@ ThreadStats =
postCountEl.textContent = postCount
fileCountEl.textContent = fileCount
(if thread.postLimit and !thread.isSticky then $.addClass else $.rmClass) postCountEl, 'warning'
(if thread.fileLimit and !thread.isSticky then $.addClass else $.rmClass) fileCountEl, 'warning'
(if thread.fileLimit and !thread.isSticky then $.addClass else $.rmClass) fileCountEl, 'warning'
fetchPage: ->
return if ThreadStats.thread.isDead or !Conf["Page Count in Stats"]
setTimeout ThreadStats.fetchPage, 2 * $.MINUTE
$.ajax "//api.4chan.org/#{ThreadStats.thread.board}/threads.json", onload: ThreadStats.onThreadsLoad,
headers: 'If-Modified-Since': ThreadStats.lastModified
onThreadsLoad: ->
return if !Conf["Page Count in Stats"]
ThreadStats.lastModified = @getResponseHeader 'Last-Modified'
return if @status isnt 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