2014-11-01 05:00:45 -04:00
|
|
|
|
/*
|
|
|
|
|
* 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';
|
|
|
|
|
*/
|
|
|
|
|
if (active_page == 'thread') {
|
2014-11-12 04:19:02 -05:00
|
|
|
|
$(document).ready(function(){
|
2014-11-01 05:00:45 -04:00
|
|
|
|
//check if page uses unique ID
|
2014-11-12 04:19:02 -05:00
|
|
|
|
var IDsupport = ($('.poster_id').length > 0);
|
2014-11-01 05:00:45 -04:00
|
|
|
|
var thread_id = (document.location.pathname + document.location.search).split('/');
|
2015-04-10 17:43:07 -04:00
|
|
|
|
thread_id = thread_id[thread_id.length -1].split('+')[0].split('-')[0].split('.')[0];
|
2014-11-01 05:00:45 -04:00
|
|
|
|
|
2015-04-10 17:11:59 -04:00
|
|
|
|
$('.boardlist.bottom, footer')
|
2014-11-01 05:00:45 -04:00
|
|
|
|
.first()
|
2015-03-11 21:22:22 -04:00
|
|
|
|
.before('<div id="thread_stats"></div>');
|
2014-11-01 05:00:45 -04:00
|
|
|
|
var el = $('#thread_stats');
|
2015-04-10 17:43:07 -04:00
|
|
|
|
el.prepend(_('Page')+' <span id="thread_stats_page">?</span>');
|
2014-11-01 05:00:45 -04:00
|
|
|
|
if (IDsupport){
|
|
|
|
|
el.prepend('<span id="thread_stats_uids">0</span> UIDs | ');
|
|
|
|
|
}
|
2015-04-10 17:43:07 -04:00
|
|
|
|
el.prepend('<span id="thread_stats_images">0</span> '+_('images')+' | ');
|
|
|
|
|
el.prepend('<span id="thread_stats_posts">0</span> '+_('replies')+' | ');
|
2014-11-01 05:00:45 -04:00
|
|
|
|
delete el;
|
2014-11-01 05:29:21 -04:00
|
|
|
|
function update_thread_stats(){
|
2014-11-01 05:00:45 -04:00
|
|
|
|
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]++;
|
2014-11-22 20:41:23 -05:00
|
|
|
|
var cur = op.find('>.intro >.poster_id');
|
|
|
|
|
cur.find('+.posts_by_id').remove();
|
|
|
|
|
cur.after('<span class="posts_by_id"> ('+ ids[cur.text()] +')</span>');
|
2014-11-01 05:00:45 -04:00
|
|
|
|
replies.each(function(){
|
2014-11-22 20:41:23 -05:00
|
|
|
|
cur = $(this).find('>.intro >.poster_id');
|
|
|
|
|
cur.find('+.posts_by_id').remove();
|
2014-11-01 05:00:45 -04:00
|
|
|
|
cur.after('<span class="posts_by_id"> ('+ ids[cur.text()] +')</span>');
|
|
|
|
|
});
|
|
|
|
|
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));
|
|
|
|
|
}
|
2015-04-10 17:11:59 -04:00
|
|
|
|
var board_name = $('input[name="board"]').val();
|
2014-11-01 05:00:45 -04:00
|
|
|
|
$.getJSON('//'+ document.location.host +'/'+ board_name +'/threads.json').success(function(data){
|
2014-11-22 02:33:42 -05:00
|
|
|
|
var found, page = '???';
|
2014-11-01 05:00:45 -04:00
|
|
|
|
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');
|
2014-11-17 04:06:56 -05:00
|
|
|
|
else $('#thread_stats_page').css('color','');
|
2014-11-01 05:00:45 -04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// 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(){
|
2015-04-10 17:11:59 -04:00
|
|
|
|
var board_name = $('input[name="board"]').val();
|
2014-11-01 05:00:45 -04:00
|
|
|
|
$.getJSON('//'+ document.location.host +'/'+ board_name +'/threads.json').success(function(data){
|
2014-11-22 02:33:42 -05:00
|
|
|
|
var found, page = '???';
|
2014-11-01 05:00:45 -04:00
|
|
|
|
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');
|
2014-11-17 04:06:56 -05:00
|
|
|
|
else $('#thread_stats_page').css('color','');
|
2014-11-01 05:00:45 -04:00
|
|
|
|
});
|
|
|
|
|
},30000);
|
|
|
|
|
$('body').append('<style>.posts_by_id{display:none;}.poster_id:hover+.posts_by_id{display:initial}</style>');
|
2014-11-01 05:29:21 -04:00
|
|
|
|
update_thread_stats();
|
2014-11-01 05:00:45 -04:00
|
|
|
|
$('#update_thread').click(update_thread_stats);
|
2014-11-01 05:29:21 -04:00
|
|
|
|
$(document).on('new_post',update_thread_stats);
|
2014-11-12 04:19:02 -05:00
|
|
|
|
});
|
|
|
|
|
}
|