From fae2e33c87d996e206e1d04dd906e667491ee8b0 Mon Sep 17 00:00:00 2001 From: ForklessAnon Date: Sat, 1 Nov 2014 04:00:45 -0500 Subject: Added script for appending thread statistics to the bottom of a thread. --- js/thread-stats.js | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 js/thread-stats.js (limited to 'js/thread-stats.js') diff --git a/js/thread-stats.js b/js/thread-stats.js new file mode 100644 index 00000000..e6fb1142 --- /dev/null +++ b/js/thread-stats.js @@ -0,0 +1,115 @@ +/* + * thread-stats.js + * - Adds statistics of the thread below the posts area + * - Shows ID post count beside each postID on hover + * + * Usage: + * $config['additional_javascript'][] = 'js/jquery.min.js'; + * $config['additional_javascript'][] = 'js/thread-stats.js'; + */ +// THREAD STATS +if (active_page == 'thread') { + + var thread_stats_timer = 30, thread_stats_timeout; //it has to be on a timer because there I haven't found a way to hook into when the actual page updates the thread... + //check if page uses unique ID + var IDsupport = ($('.poster_id').length > 0); + var thread_id = (document.location.pathname + document.location.search).split('/'); + thread_id = thread_id[thread_id.length -1].split('+')[0].split('.')[0]; + + $('form[name="postcontrols"] > .delete') + .first() + .before('
'); + var el = $('#thread_stats'); + el.prepend('Page ?'); + if (IDsupport){ + el.prepend('0 UIDs | '); + } + el.prepend('0 images | '); + el.prepend('0 replies | '); + delete el; + function update_thread_stats(force){ + var op = $('#thread_'+ thread_id +' > div.post.op:not(.post-hover):not(.inline)').first(); + var replies = $('#thread_'+ thread_id +' > div.post.reply:not(.post-hover):not(.inline)'); + // post count + $('#thread_stats_posts').text(replies.length); + // image count + $('#thread_stats_images').text(replies.filter(function(){ + return $(this).find('> .files').text().trim() != false; + }).length); + // unique ID count + if (IDsupport) { + var opID = op.find('> .intro > .poster_id').text(); + var ids = {}; + replies.each(function(){ + var cur = $(this).find('> .intro > .poster_id'); + var curID = cur.text(); + if (ids[curID] === undefined) { + ids[curID] = 0; + } + ids[curID]++; + }); + if (ids[opID] === undefined) { + ids[opID] = 0; + } + ids[opID]++; + replies.each(function(){ + var cur = $(this).find('> .intro > .poster_id'); + cur.find('+ .posts_by_id').remove(); + cur.after(' ('+ ids[cur.text()] +')'); + }); + var size = function(obj) { + var size = 0, key; + for (key in obj) { + if (obj.hasOwnProperty(key)) size++; + } + return size; + }; + $('#thread_stats_uids').text(size(ids)); + } + $.getJSON('//'+ document.location.host +'/'+ board_name +'/threads.json').success(function(data){ + var found, page = 'Pruned or Deleted'; + for (var i=0;data[i];i++){ + var threads = data[i].threads; + for (var j=0; threads[j]; j++){ + if (parseInt(threads[j].no) == parseInt(thread_id)) { + page = data[i].page +1; + found = true; + break; + } + } + if (found) break; + } + $('#thread_stats_page').text(page); + if (!found) $('#thread_stats_page').css('color','red'); + }); + } + // load the current page the thread is on. + // uses ajax call so it gets loaded on a delay (depending on network resources available) + var thread_stats_page_timer = setInterval(function(){ + $.getJSON('//'+ document.location.host +'/'+ board_name +'/threads.json').success(function(data){ + var found, page = 'Pruned or Deleted'; + for (var i=0;data[i];i++){ + var threads = data[i].threads; + for (var j=0; threads[j]; j++){ + if (parseInt(threads[j].no) == parseInt(thread_id)) { + page = data[i].page +1; + found = true; + break; + } + } + if (found) break; + } + $('#thread_stats_page').text(page); + if (!found) $('#thread_stats_page').css('color','red'); + }); + + },30000); + $(document).ready(function(){ + $('body').append(''); + update_thread_stats(true); + $('#update_thread').click(update_thread_stats); + MutationObserver = window.MutationObserver || window.WebKitMutationObserver; + var observer = new MutationObserver(function(mutations, observer){update_thread_stats();}); + observer.observe($('#thread_' + thread_id)[0], {childList: true}); + }); +} \ No newline at end of file -- cgit v1.3 From 8d451280306c4f05ebb966399420ae4f08831965 Mon Sep 17 00:00:00 2001 From: ForklessAnon Date: Sat, 1 Nov 2014 04:29:21 -0500 Subject: Some code cleanup on thread stats. --- js/thread-stats.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'js/thread-stats.js') diff --git a/js/thread-stats.js b/js/thread-stats.js index e6fb1142..59fed912 100644 --- a/js/thread-stats.js +++ b/js/thread-stats.js @@ -7,10 +7,7 @@ * $config['additional_javascript'][] = 'js/jquery.min.js'; * $config['additional_javascript'][] = 'js/thread-stats.js'; */ -// THREAD STATS if (active_page == 'thread') { - - var thread_stats_timer = 30, thread_stats_timeout; //it has to be on a timer because there I haven't found a way to hook into when the actual page updates the thread... //check if page uses unique ID var IDsupport = ($('.poster_id').length > 0); var thread_id = (document.location.pathname + document.location.search).split('/'); @@ -27,7 +24,7 @@ if (active_page == 'thread') { el.prepend('0 images | '); el.prepend('0 replies | '); delete el; - function update_thread_stats(force){ + function update_thread_stats(){ var op = $('#thread_'+ thread_id +' > div.post.op:not(.post-hover):not(.inline)').first(); var replies = $('#thread_'+ thread_id +' > div.post.reply:not(.post-hover):not(.inline)'); // post count @@ -102,14 +99,11 @@ if (active_page == 'thread') { $('#thread_stats_page').text(page); if (!found) $('#thread_stats_page').css('color','red'); }); - },30000); $(document).ready(function(){ $('body').append(''); - update_thread_stats(true); + update_thread_stats(); $('#update_thread').click(update_thread_stats); - MutationObserver = window.MutationObserver || window.WebKitMutationObserver; - var observer = new MutationObserver(function(mutations, observer){update_thread_stats();}); - observer.observe($('#thread_' + thread_id)[0], {childList: true}); + $(document).on('new_post',update_thread_stats); }); } \ No newline at end of file -- cgit v1.3 From 1aa8f6251d30545242768bf13bbe9ee89c231ca7 Mon Sep 17 00:00:00 2001 From: 8chan Date: Wed, 12 Nov 2014 01:19:02 -0800 Subject: Have to load onready --- js/thread-stats.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'js/thread-stats.js') diff --git a/js/thread-stats.js b/js/thread-stats.js index 59fed912..4050fb67 100644 --- a/js/thread-stats.js +++ b/js/thread-stats.js @@ -8,8 +8,9 @@ * $config['additional_javascript'][] = 'js/thread-stats.js'; */ if (active_page == 'thread') { +$(document).ready(function(){ //check if page uses unique ID - var IDsupport = ($('.poster_id').length > 0); + var IDsupport = ($('.poster_id').length > 0); var thread_id = (document.location.pathname + document.location.search).split('/'); thread_id = thread_id[thread_id.length -1].split('+')[0].split('.')[0]; @@ -100,10 +101,9 @@ if (active_page == 'thread') { if (!found) $('#thread_stats_page').css('color','red'); }); },30000); - $(document).ready(function(){ $('body').append(''); update_thread_stats(); $('#update_thread').click(update_thread_stats); $(document).on('new_post',update_thread_stats); - }); -} \ No newline at end of file +}); +} -- cgit v1.3 From fdc14c699c25131ffe25536928e0dfac990c4ae3 Mon Sep 17 00:00:00 2001 From: Forkless Date: Mon, 17 Nov 2014 03:06:56 -0600 Subject: Fix color incase page is missed and then found again. --- js/thread-stats.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'js/thread-stats.js') diff --git a/js/thread-stats.js b/js/thread-stats.js index 4050fb67..7c13d66c 100644 --- a/js/thread-stats.js +++ b/js/thread-stats.js @@ -79,6 +79,7 @@ $(document).ready(function(){ } $('#thread_stats_page').text(page); if (!found) $('#thread_stats_page').css('color','red'); + else $('#thread_stats_page').css('color',''); }); } // load the current page the thread is on. @@ -99,6 +100,7 @@ $(document).ready(function(){ } $('#thread_stats_page').text(page); if (!found) $('#thread_stats_page').css('color','red'); + else $('#thread_stats_page').css('color',''); }); },30000); $('body').append(''); -- cgit v1.3 From cf91daee7cfbdbede0e0d01b40dd7879cab88186 Mon Sep 17 00:00:00 2001 From: 8chan Date: Fri, 21 Nov 2014 23:33:42 -0800 Subject: No need to display pruned in two places...especially if server times out / errors --- js/thread-stats.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/thread-stats.js') diff --git a/js/thread-stats.js b/js/thread-stats.js index 7c13d66c..1785b79a 100644 --- a/js/thread-stats.js +++ b/js/thread-stats.js @@ -65,7 +65,7 @@ $(document).ready(function(){ $('#thread_stats_uids').text(size(ids)); } $.getJSON('//'+ document.location.host +'/'+ board_name +'/threads.json').success(function(data){ - var found, page = 'Pruned or Deleted'; + var found, page = '???'; for (var i=0;data[i];i++){ var threads = data[i].threads; for (var j=0; threads[j]; j++){ @@ -86,7 +86,7 @@ $(document).ready(function(){ // uses ajax call so it gets loaded on a delay (depending on network resources available) var thread_stats_page_timer = setInterval(function(){ $.getJSON('//'+ document.location.host +'/'+ board_name +'/threads.json').success(function(data){ - var found, page = 'Pruned or Deleted'; + var found, page = '???'; for (var i=0;data[i];i++){ var threads = data[i].threads; for (var j=0; threads[j]; j++){ -- cgit v1.3 From 4b782d6163d061e394e857d6c4f1a94391ddf01b Mon Sep 17 00:00:00 2001 From: Forkless Date: Sat, 22 Nov 2014 19:41:23 -0600 Subject: Fix thread stats so post count hover works on the OP's id. --- js/thread-stats.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'js/thread-stats.js') diff --git a/js/thread-stats.js b/js/thread-stats.js index 1785b79a..9b9b3cb3 100644 --- a/js/thread-stats.js +++ b/js/thread-stats.js @@ -50,9 +50,12 @@ $(document).ready(function(){ ids[opID] = 0; } ids[opID]++; + var cur = op.find('>.intro >.poster_id'); + cur.find('+.posts_by_id').remove(); + cur.after(' ('+ ids[cur.text()] +')'); replies.each(function(){ - var cur = $(this).find('> .intro > .poster_id'); - cur.find('+ .posts_by_id').remove(); + cur = $(this).find('>.intro >.poster_id'); + cur.find('+.posts_by_id').remove(); cur.after(' ('+ ids[cur.text()] +')'); }); var size = function(obj) { -- cgit v1.3 From c4fc8273328a7d4955e472e3242837a4e210adaf Mon Sep 17 00:00:00 2001 From: 8chan Date: Wed, 11 Mar 2015 18:22:22 -0700 Subject: some style fixes Conflicts: templates/8chan/boards-tags.html --- js/thread-stats.js | 2 +- stylesheets/dark.css | 8 ++++++-- stylesheets/photon.css | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) (limited to 'js/thread-stats.js') diff --git a/js/thread-stats.js b/js/thread-stats.js index 9b9b3cb3..fb520c71 100644 --- a/js/thread-stats.js +++ b/js/thread-stats.js @@ -16,7 +16,7 @@ $(document).ready(function(){ $('form[name="postcontrols"] > .delete') .first() - .before('
'); + .before('
'); var el = $('#thread_stats'); el.prepend('Page ?'); if (IDsupport){ diff --git a/stylesheets/dark.css b/stylesheets/dark.css index 7fc4e199..beb12364 100644 --- a/stylesheets/dark.css +++ b/stylesheets/dark.css @@ -166,13 +166,13 @@ table.modlog tr th { color: #AAAAAA; } -.desktop-style div.boardlist:nth-child(1) { +.desktop-style div.boardlist:not(.bottom) { text-shadow: black 1px 1px 1px, black -1px -1px 1px, black -1px 1px 1px, black 1px -1px 1px; background-color: #666666; } -.desktop-style div.boardlist:nth-child(1):hover, .desktop-style div.boardlist:nth-child(1).cb-menu { +.desktop-style div.boardlist:not(.bottom):hover, .desktop-style div.boardlist:not(.bottom).cb-menu { background-color: rgba(30%, 30%, 30%, 0.65); } @@ -190,3 +190,7 @@ div.report { .options_tab_icon.active { color: #FFFFFF; } + +#quick-reply table { + background: none repeat scroll 0% 0% #333 !important; +} diff --git a/stylesheets/photon.css b/stylesheets/photon.css index db189d77..a487e4dd 100644 --- a/stylesheets/photon.css +++ b/stylesheets/photon.css @@ -326,6 +326,6 @@ form table tr td div { padding: 0px !important; } -.desktop-style div.boardlist:nth-child(1) { +.desktop-style div.boardlist:not(.bottom) { background-color: #DDDDDD; } -- cgit v1.3 From 0d0b2fcd7e807f50b621c17e153194cf99edef5b Mon Sep 17 00:00:00 2001 From: czaks Date: Fri, 10 Apr 2015 23:11:59 +0200 Subject: thread-stats.js: vichan fixes --- js/thread-stats.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'js/thread-stats.js') diff --git a/js/thread-stats.js b/js/thread-stats.js index fb520c71..f3b2d375 100644 --- a/js/thread-stats.js +++ b/js/thread-stats.js @@ -12,9 +12,9 @@ $(document).ready(function(){ //check if page uses unique ID var IDsupport = ($('.poster_id').length > 0); var thread_id = (document.location.pathname + document.location.search).split('/'); - thread_id = thread_id[thread_id.length -1].split('+')[0].split('.')[0]; + thread_id = thread_id[thread_id.length -1].split(/+-/)[0].split('.')[0]; - $('form[name="postcontrols"] > .delete') + $('.boardlist.bottom, footer') .first() .before('
'); var el = $('#thread_stats'); @@ -67,6 +67,7 @@ $(document).ready(function(){ }; $('#thread_stats_uids').text(size(ids)); } + var board_name = $('input[name="board"]').val(); $.getJSON('//'+ document.location.host +'/'+ board_name +'/threads.json').success(function(data){ var found, page = '???'; for (var i=0;data[i];i++){ @@ -88,6 +89,7 @@ $(document).ready(function(){ // load the current page the thread is on. // uses ajax call so it gets loaded on a delay (depending on network resources available) var thread_stats_page_timer = setInterval(function(){ + var board_name = $('input[name="board"]').val(); $.getJSON('//'+ document.location.host +'/'+ board_name +'/threads.json').success(function(data){ var found, page = '???'; for (var i=0;data[i];i++){ -- cgit v1.3 From c4569b2ea55d162716cda443c7f28ceed672e0eb Mon Sep 17 00:00:00 2001 From: czaks Date: Fri, 10 Apr 2015 23:13:52 +0200 Subject: thread-stats.js: code typo :^) --- js/thread-stats.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/thread-stats.js') diff --git a/js/thread-stats.js b/js/thread-stats.js index f3b2d375..6035de04 100644 --- a/js/thread-stats.js +++ b/js/thread-stats.js @@ -12,7 +12,7 @@ $(document).ready(function(){ //check if page uses unique ID var IDsupport = ($('.poster_id').length > 0); var thread_id = (document.location.pathname + document.location.search).split('/'); - thread_id = thread_id[thread_id.length -1].split(/+-/)[0].split('.')[0]; + thread_id = thread_id[thread_id.length -1].split(/\+-/)[0].split('.')[0]; $('.boardlist.bottom, footer') .first() -- cgit v1.3 From bdda1613a6bc4b88dfe9027dc0f330194654ad9c Mon Sep 17 00:00:00 2001 From: czaks Date: Fri, 10 Apr 2015 23:43:07 +0200 Subject: thread-stats.js: final vichan fix, should work now --- js/thread-stats.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'js/thread-stats.js') diff --git a/js/thread-stats.js b/js/thread-stats.js index 6035de04..8873dbdb 100644 --- a/js/thread-stats.js +++ b/js/thread-stats.js @@ -12,18 +12,18 @@ $(document).ready(function(){ //check if page uses unique ID var IDsupport = ($('.poster_id').length > 0); var thread_id = (document.location.pathname + document.location.search).split('/'); - thread_id = thread_id[thread_id.length -1].split(/\+-/)[0].split('.')[0]; + thread_id = thread_id[thread_id.length -1].split('+')[0].split('-')[0].split('.')[0]; $('.boardlist.bottom, footer') .first() .before('
'); var el = $('#thread_stats'); - el.prepend('Page ?'); + el.prepend(_('Page')+' ?'); if (IDsupport){ el.prepend('0 UIDs | '); } - el.prepend('0 images | '); - el.prepend('0 replies | '); + el.prepend('0 '+_('images')+' | '); + el.prepend('0 '+_('replies')+' | '); delete el; function update_thread_stats(){ var op = $('#thread_'+ thread_id +' > div.post.op:not(.post-hover):not(.inline)').first(); -- cgit v1.3