Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.