diff --git a/LICENSE b/LICENSE index f61eb8a33..1ab2d4758 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/builds/4chan-X.js b/builds/4chan-X.js index 9da652217..c2238eaa6 100644 --- a/builds/4chan-X.js +++ b/builds/4chan-X.js @@ -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: "0 / 0", - id: 'thread-stats' + innerHTML: "0 / 0" + (Conf["Page Count in Stats"] ? " / 0" : ""), + 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;', "
0 / 0
"); + this.dialog = sc = UI.dialog('thread-stats', 'bottom: 0px; right: 0px;', "
0 / 0" + (Conf["Page Count in Stats"] ? " / 0" : "") + "
"); $.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; + } + } + } } }; diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index e547df7d0..16743b31f 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -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: "0 / 0", - id: 'thread-stats' + innerHTML: "0 / 0" + (Conf["Page Count in Stats"] ? " / 0" : ""), + 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;', "
0 / 0
"); + this.dialog = sc = UI.dialog('thread-stats', 'bottom: 0px; right: 0px;', "
0 / 0" + (Conf["Page Count in Stats"] ? " / 0" : "") + "
"); $.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; + } + } + } } }; diff --git a/builds/crx/script.js b/builds/crx/script.js index 9daf378ea..6d43d55ab 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -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: "0 / 0", - id: 'thread-stats' + innerHTML: "0 / 0" + (Conf["Page Count in Stats"] ? " / 0" : ""), + 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;', "
0 / 0
"); + this.dialog = sc = UI.dialog('thread-stats', 'bottom: 0px; right: 0px;', "
0 / 0" + (Conf["Page Count in Stats"] ? " / 0" : "") + "
"); $.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; + } + } + } } }; diff --git a/src/General/Config.coffee b/src/General/Config.coffee index d403e0b8f..4e1bdd996 100644 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -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.' diff --git a/src/Monitoring/ThreadStats.coffee b/src/Monitoring/ThreadStats.coffee index 7cb857ca5..8a3c586d9 100644 --- a/src/Monitoring/ThreadStats.coffee +++ b/src/Monitoring/ThreadStats.coffee @@ -4,18 +4,21 @@ ThreadStats = if Conf['Updater and Stats in Header'] @dialog = sc = $.el 'span', - innerHTML: "0 / 0" + innerHTML: "0 / 0#{if Conf["Page Count in Stats"] then " / 0" 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;', - "
0 / 0
" + "
0 / 0#{if Conf["Page Count in Stats"] then " / 0" else ""}
" $.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' \ No newline at end of file + (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 \ No newline at end of file