Skip to content

Instantly share code, notes, and snippets.

@Phoenix616
Last active August 20, 2021 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Phoenix616/c757c627c5f3507b42b294caa948a17d to your computer and use it in GitHub Desktop.
Save Phoenix616/c757c627c5f3507b42b294caa948a17d to your computer and use it in GitHub Desktop.
SpigotMC.org/Xenforo Resource Manager weighted rating display ‒ Used formula: (10 * 3 + averageRating * ratingCount) / (10 + ratingCount)
// ==UserScript==
// @name SpigotMC weighted ratings display
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Display the weighted rating of a Xenforo Resource Manager resource which is used for sorting
// @author Phoenix616
// @match https://www.spigotmc.org/resources/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var resourceListItems = document.getElementsByClassName("resourceListItem");
if (resourceListItems !== null) {
for (var i = 0; i < resourceListItems.length; i++) {
addRealRating(resourceListItems[i]);
}
}
var resourceInfo = document.getElementById("resourceInfo");
if (resourceInfo !== null) {
addRealRating(resourceInfo);
}
function addRealRating(e){
var ratingNode = e.getElementsByClassName("rating")[0];
var averageRating = parseFloat(ratingNode.getElementsByClassName("Number")[0].innerText);
if (averageRating == 0) {
return;
}
var hintNode = ratingNode.getElementsByClassName("Hint")[0];
var ratingsCount = parseInt(hintNode.innerText.split(" ")[0]);
var realRating = (10 * 3 + averageRating * ratingsCount) / (10 + ratingsCount);
var realRatingNode = document.createElement("SPAN");
realRatingNode.innerText = Math.round(realRating*1000)/1000;
hintNode.parentNode.insertBefore(realRatingNode, hintNode);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment