Advertisement
Guest User

MoA - Thread totals

a guest
Jan 26th, 2024
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. // ==UserScript==
  2. // @name MoA - Thread totals
  3. // @description Count posters and comments in MoA
  4. // @namespace https://www.greasespot.net/
  5. // @author aletsan
  6. // @version 1.0
  7. // @match https://www.moonofalabama.org/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. // A script to display to top posters and their posts count in a small footer on the current page
  12. // It adds all the posts of every poster in the page, sorts it by count descending and name ascending and displays all that have more than 1 post in a footer
  13. // It works only for the displayed page and not for the total posts of a thread, if you need total number you must go through all pages and do the sum by hand
  14. // The code needed for adding the count going up/down the comments pages of a thread is a bit much and there are things that may not work correctly slowing down of even breaking the code
  15. // You can change the footer info line properties to your liking and have it displayed as you like
  16.  
  17. (function(){
  18. 'use strict';
  19.  
  20. // the script will run only if we are in a page that has comments
  21. if(document.getElementsByClassName("comments-body").length>0)
  22. {
  23. // get the list of comments in page
  24. const commentslist = document.getElementsByClassName("comments-body");
  25.  
  26. // create array for usernames and posts count
  27. let postscountarray = [];
  28.  
  29. // process the comments list
  30. for(let comment of commentslist)
  31. {
  32. // get the poster info line from comment
  33. let posterinfo = comment.getElementsByClassName('posted')[0];
  34.  
  35. // extract username from poster info line and remove before/after whitespaces
  36. let username1 = posterinfo.textContent.split('|',1);
  37. let username2 = username1[0].split(':');
  38. let usernamefinal = username2[1].trim();
  39. // adding poster in count array:
  40. // search if poster's name is already in the array
  41. let searchedid = postscountarray.map(e => e.name).indexOf(usernamefinal);
  42. // if he does not exists then it's his 1st post so just add his name and make his count 1
  43. if (searchedid == -1)
  44. {
  45. let postscountentry = {name:usernamefinal,count:1};
  46. postscountarray.push(postscountentry);
  47. }
  48. // if he already exist then it's another post from him so go to his entry and increase his count by 1
  49. else
  50. {
  51. postscountarray[searchedid].count++;
  52. }
  53. }
  54.  
  55. // sort posts count array by number of posts descending and names ascending
  56. postscountarray.sort((a, b) => b.count - a.count || a.name.localeCompare(b.name));
  57.  
  58. // create new array of posters with more than 1 post from original array
  59. let searchedcountid = postscountarray.map(e => e.count).indexOf(1);
  60. let multiposters = postscountarray.slice(0,searchedcountid);
  61.  
  62. // create the text to display in the footer
  63. let multiposterstext = "";
  64. // if we actually have multiposters process their array
  65. if (multiposters.length>0)
  66. {
  67. // create footer info text from multiposters array
  68. multiposterstext = multiposters[0].name+"("+multiposters[0].count.toString()+")";
  69. for (var i=1; i<multiposters.length; i++)
  70. {
  71. multiposterstext += ", "+multiposters[i].name+"("+multiposters[i].count.toString()+")";
  72. }
  73. }
  74. //if we don't have multiposters just inform about it
  75. else
  76. {
  77. multiposterstext = "No multiposters";
  78. }
  79.  
  80. // add the info in a "sticky" footer
  81. var footerinfo=document.createElement('div');
  82. footerinfo.innerHTML='<div id="thread-posting-totals-added" style="font-size:14px;font-style:italic;color:Black;background:LightGray;position:fixed;bottom:0;width:100%;padding:5px;border-top-width:1px;border-top-style:solid;">' + multiposterstext + '</div>';
  83. document.body.appendChild(footerinfo);
  84. }
  85. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement