Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name MoA - Thread totals
- // @description Count posters and comments in MoA
- // @namespace https://www.greasespot.net/
- // @author aletsan
- // @version 1.0
- // @match https://www.moonofalabama.org/*
- // @grant none
- // ==/UserScript==
- // A script to display to top posters and their posts count in a small footer on the current page
- // 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
- // 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
- // 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
- // You can change the footer info line properties to your liking and have it displayed as you like
- (function(){
- 'use strict';
- // the script will run only if we are in a page that has comments
- if(document.getElementsByClassName("comments-body").length>0)
- {
- // get the list of comments in page
- const commentslist = document.getElementsByClassName("comments-body");
- // create array for usernames and posts count
- let postscountarray = [];
- // process the comments list
- for(let comment of commentslist)
- {
- // get the poster info line from comment
- let posterinfo = comment.getElementsByClassName('posted')[0];
- // extract username from poster info line and remove before/after whitespaces
- let username1 = posterinfo.textContent.split('|',1);
- let username2 = username1[0].split(':');
- let usernamefinal = username2[1].trim();
- // adding poster in count array:
- // search if poster's name is already in the array
- let searchedid = postscountarray.map(e => e.name).indexOf(usernamefinal);
- // if he does not exists then it's his 1st post so just add his name and make his count 1
- if (searchedid == -1)
- {
- let postscountentry = {name:usernamefinal,count:1};
- postscountarray.push(postscountentry);
- }
- // if he already exist then it's another post from him so go to his entry and increase his count by 1
- else
- {
- postscountarray[searchedid].count++;
- }
- }
- // sort posts count array by number of posts descending and names ascending
- postscountarray.sort((a, b) => b.count - a.count || a.name.localeCompare(b.name));
- // create new array of posters with more than 1 post from original array
- let searchedcountid = postscountarray.map(e => e.count).indexOf(1);
- let multiposters = postscountarray.slice(0,searchedcountid);
- // create the text to display in the footer
- let multiposterstext = "";
- // if we actually have multiposters process their array
- if (multiposters.length>0)
- {
- // create footer info text from multiposters array
- multiposterstext = multiposters[0].name+"("+multiposters[0].count.toString()+")";
- for (var i=1; i<multiposters.length; i++)
- {
- multiposterstext += ", "+multiposters[i].name+"("+multiposters[i].count.toString()+")";
- }
- }
- //if we don't have multiposters just inform about it
- else
- {
- multiposterstext = "No multiposters";
- }
- // add the info in a "sticky" footer
- var footerinfo=document.createElement('div');
- 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>';
- document.body.appendChild(footerinfo);
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement