RYM 5 star ratio

Displays the ratio of 5 star ratings on an album.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==UserScript==
// @name         RYM 5 star ratio
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  Displays the ratio of 5 star ratings on an album.
// @author       You
// @match        https://rateyourmusic.com/release/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=rateyourmusic.com
// @grant        none
// ==/UserScript==

// ==UserScript==
// @name         RYM 5 star ratio
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Displays the ratio of 5 star ratings on an album.
// @author       You
// @match        https://rateyourmusic.com/release/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=rateyourmusic.com
// @grant        none
// @downloadURL https://update.greasyfork.org/scripts/473783/RYM%205%20star%20ratio.user.js
// @updateURL https://update.greasyfork.org/scripts/473783/RYM%205%20star%20ratio.meta.js
// ==/UserScript==

(function() {
    'use strict';

    function injectRatio() {
        const numRatingsElement = document.querySelector('.num_ratings');
        const totalRatingsSpan = numRatingsElement?.querySelector('span');
        const chartDiv = document.getElementById('chart_div');
        const tdElements = chartDiv?.querySelectorAll('td');

        if (
            numRatingsElement &&
            totalRatingsSpan &&
            chartDiv &&
            tdElements &&
            tdElements.length > 0 &&
            !numRatingsElement.dataset.injected
        ) {
            const totalRatings = Number(totalRatingsSpan.innerText.replace(/,/g, ''));
            const fiveStarRatings = Number(tdElements[tdElements.length - 1].innerText.replace(/,/g, ''));
            const calculatedValue = fiveStarRatings / totalRatings * 100;

            numRatingsElement.innerHTML += ' (' + calculatedValue.toFixed(2) + '%)';
            numRatingsElement.dataset.injected = 'true'; // Mark as injected
        }
    }

    const observer = new MutationObserver(() => {
        injectRatio();
    });

    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

    // Initial attempt in case everything is already loaded
    injectRatio();
})();