// ==UserScript== // @name RYM Star Rating // @namespace http://rateyourmusic.com/ // @version 2024-07-02 // @description Adds an artist rating based on the average of their entire discography // @author Michael Santos // @match https://rateyourmusic.com/artist/* // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; // Select all divs with the specified classes const divs = document.querySelectorAll('div.disco_avg_rating.enough_data'); // Extract the text content and convert to floats const ratings = Array.from(divs).map(div => parseFloat(div.textContent)); // Calculate the average const average = ratings.reduce((sum, rating) => sum + rating, 0) / ratings.length; // Round the average to two decimal places const roundedAverage = average.toFixed(2); // Create new elements to append const starRatingHeader = document.createElement('div'); starRatingHeader.className = 'info_hdr'; starRatingHeader.textContent = 'Star rating'; const starRatingContent = document.createElement('div'); starRatingContent.className = 'info_content'; starRatingContent.innerHTML = `${roundedAverage}`; // Append the new elements at the beginning of the artist_info_main div const artistInfoMain = document.querySelector('div.artist_info_main'); artistInfoMain.insertBefore(starRatingContent, artistInfoMain.firstChild); artistInfoMain.insertBefore(starRatingHeader, artistInfoMain.firstChild); })();