The version of vichan running on lainchan.org
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

114 řádky
3.8KB

  1. /*
  2. * thread-stats.js
  3. * - Adds statistics of the thread below the posts area
  4. * - Shows ID post count beside each postID on hover
  5. *
  6. * Usage:
  7. * $config['additional_javascript'][] = 'js/jquery.min.js';
  8. * $config['additional_javascript'][] = 'js/thread-stats.js';
  9. */
  10. if (active_page == 'thread') {
  11. $(document).ready(function(){
  12. //check if page uses unique ID
  13. var IDsupport = ($('.poster_id').length > 0);
  14. var thread_id = (document.location.pathname + document.location.search).split('/');
  15. thread_id = thread_id[thread_id.length -1].split('+')[0].split('.')[0];
  16. $('.clear')
  17. .before('<div id="thread_stats"></div>');
  18. var el = $('#thread_stats');
  19. el.prepend('Page <span id="thread_stats_page">?</span>');
  20. if (IDsupport){
  21. el.prepend('<span id="thread_stats_uids">0</span> UIDs |&nbsp;');
  22. }
  23. el.prepend('<span id="thread_stats_images">0</span> images |&nbsp;');
  24. el.prepend('<span id="thread_stats_posts">0</span> replies |&nbsp;');
  25. delete el;
  26. function update_thread_stats(){
  27. var op = $('#thread_'+ thread_id).find('div.post.op:not(.post-hover):not(.inline)').first();
  28. var replies = $('#thread_'+ thread_id).find('div.post.reply:not(.post-hover):not(.inline)');
  29. // post count
  30. $('#thread_stats_posts').text(replies.length);
  31. // image count
  32. $('#thread_stats_images').text(replies.filter(function(){
  33. return $(this).find('> .files').text().trim() != false;
  34. }).length);
  35. // unique ID count
  36. if (IDsupport) {
  37. var opID = op.find('> .intro > .poster_id').text();
  38. var ids = {};
  39. replies.each(function(){
  40. var cur = $(this).find('> .intro > .poster_id');
  41. var curID = cur.text();
  42. if (ids[curID] === undefined) {
  43. ids[curID] = 0;
  44. }
  45. ids[curID]++;
  46. });
  47. if (ids[opID] === undefined) {
  48. ids[opID] = 0;
  49. }
  50. ids[opID]++;
  51. var cur = op.find('>.intro >.poster_id');
  52. cur.find('+.posts_by_id').remove();
  53. cur.after('<span class="posts_by_id"> ('+ ids[cur.text()] +')</span>');
  54. replies.each(function(){
  55. cur = $(this).find('>.intro >.poster_id');
  56. cur.find('+.posts_by_id').remove();
  57. cur.after('<span class="posts_by_id"> ('+ ids[cur.text()] +')</span>');
  58. });
  59. var size = function(obj) {
  60. var size = 0, key;
  61. for (key in obj) {
  62. if (obj.hasOwnProperty(key)) size++;
  63. }
  64. return size;
  65. };
  66. $('#thread_stats_uids').text(size(ids));
  67. }
  68. $.getJSON('//'+ document.location.host +'/'+ board_name +'/threads.json').success(function(data){
  69. var found, page = '???';
  70. for (var i=0;data[i];i++){
  71. var threads = data[i].threads;
  72. for (var j=0; threads[j]; j++){
  73. if (parseInt(threads[j].no) == parseInt(thread_id)) {
  74. page = data[i].page +1;
  75. found = true;
  76. break;
  77. }
  78. }
  79. if (found) break;
  80. }
  81. $('#thread_stats_page').text(page);
  82. if (!found) $('#thread_stats_page').css('color','red');
  83. else $('#thread_stats_page').css('color','');
  84. });
  85. }
  86. // load the current page the thread is on.
  87. // uses ajax call so it gets loaded on a delay (depending on network resources available)
  88. var thread_stats_page_timer = setInterval(function(){
  89. $.getJSON('//'+ document.location.host +'/'+ board_name +'/threads.json').success(function(data){
  90. var found, page = '???';
  91. for (var i=0;data[i];i++){
  92. var threads = data[i].threads;
  93. for (var j=0; threads[j]; j++){
  94. if (parseInt(threads[j].no) == parseInt(thread_id)) {
  95. page = data[i].page +1;
  96. found = true;
  97. break;
  98. }
  99. }
  100. if (found) break;
  101. }
  102. $('#thread_stats_page').text(page);
  103. if (!found) $('#thread_stats_page').css('color','red');
  104. else $('#thread_stats_page').css('color','');
  105. });
  106. },30000);
  107. $('body').append('<style>.posts_by_id{display:none;}.poster_id:hover+.posts_by_id{display:initial}</style>');
  108. update_thread_stats();
  109. $('#update_thread').click(update_thread_stats);
  110. $(document).on('new_post',update_thread_stats);
  111. });
  112. }