Greasy Fork

Greasy Fork is available in English.

RYM Star Rating

Adds an artist rating based on the average of their entire discography

当前为 2024-07-02 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         RYM Star Rating
// @namespace    http://rateyourmusic.com/
// @version      2.0.0
// @description  Adds an artist rating based on the average of their entire discography
// @author       Michael Santos
// @match        https://rateyourmusic.com/artist/*
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Select all divs with the specified classes
    const divs = document.querySelectorAll('div.disco_avg_rating');

    // Extract the text content and convert to floats
    const ratings = Array.from(divs)
      .map(div => div.textContent.trim())
      .filter(text => text !== '')
      .map(text => parseFloat(text));

    // 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 = `<b>${roundedAverage}</b>`;

    // 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);
})();