RYM User Reception

Create a section illustrating the user reception of the release on RateYourMusic

目前為 2025-06-07 提交的版本,檢視 最新版本

// ==UserScript==
// @name         RYM User Reception
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Create a section illustrating the user reception of the release on RateYourMusic
// @author       https://gf.qytechs.cn/users/1320826-polachek
// @match        https://rateyourmusic.com/release/*
// @match        https://rateyourmusic.com/film/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=rateyourmusic.com
// @grant        GM_addStyle
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    GM_addStyle(`
        .rym-reception {
            margin-top: 0px;
            line-height: 1.8;
            padding: 10px 0;
            border-top: 1px solid var(--mono-d);
        }
        .rym-reception div {
            display: flex;
            align-items: center;
            font-family: var(--font-family-sans-serif);
            transition: font-size 0.3s;
        }
        .rym-reception .emoji {
            margin-right: 8px;
            font-size: 1.2em;
        }
        .rym-reception .top-item {
            font-size: 1.2em;
            font-weight: bold;
            margin-bottom: 5px;
        }
        .rym-reception .other-items {
            font-size: 0.95em;
            opacity: 0.9;
        }
    `);

    function initUserReception() {
        const statsContainer = $('.catalog_stats.hide-for-small');
        if (!statsContainer.length) return;

        let chartData = [];
        const hiddenTable = $('#chart_div table');

        if (hiddenTable.length) {
            hiddenTable.find('tbody tr').each(function() {
                const rating = parseFloat($(this).find('td:first').text().trim());
                const count = parseInt($(this).find('td:last').text().trim());
                if (!isNaN(rating) && !isNaN(count)) {
                    chartData.push([rating, count]);
                }
            });
        }

        if (chartData.length === 0) {
            const scriptContent = $('script:contains("drawChart1")').text();
            const regex = /data\.addRows\(\[([\s\S]*?)\]\)/;
            const match = scriptContent.match(regex);

            if (match && match[1]) {
                try {
                    const dataString = '[' + match[1].replace(/\s/g, '') + ']';
                    chartData = JSON.parse(dataString);
                } catch (e) {
                    console.error('RYM User Reception: Erro ao analisar dados', e);
                    return;
                }
            }
        }

        if (chartData.length === 0) return;

        const categoryMap = {
            'loved it': [5.0],
            'really liked it': [4.0, 4.5],
            'liked it': [3.0, 3.5],
            'tolerated it': [2.5],
            'didn\'t like it': [1.5, 2.0],
            'despised it': [0.5, 1.0]
        };

        const emojiMap = {
            'loved it': '🥰',
            'really liked it': '🤩',
            'liked it': '😏',
            'tolerated it': '😐',
            'didn\'t like it': '😒',
            'despised it': '😖'
        };

        const categoryCounts = {};
        let total = 0;

        Object.keys(categoryMap).forEach(category => {
            categoryCounts[category] = 0;
        });

        chartData.forEach(([rating, count]) => {
            for (const [category, ratings] of Object.entries(categoryMap)) {
                if (ratings.includes(rating)) {
                    categoryCounts[category] += count;
                    total += count;
                    break;
                }
            }
        });

        if (total === 0) return;

        const receptionData = [];
        Object.keys(categoryCounts).forEach(category => {
            const percentage = ((categoryCounts[category] / total) * 100).toFixed(1);
            receptionData.push({
                category,
                percentage,
                emoji: emojiMap[category]
            });
        });

        receptionData.sort((a, b) => parseFloat(b.percentage) - parseFloat(a.percentage));

        let topItemHTML = '';
        let otherItemsHTML = '';

        receptionData.forEach((item, index) => {
            const line = `<div><span class="emoji">${item.emoji}</span> ${item.percentage}% ${item.category}</div>`;

            if (index === 0) {
                topItemHTML = `<div class="top-item">${line}</div>`;
            } else {
                otherItemsHTML += `<div class="other-items">${line}</div>`;
            }
        });

        const sectionHTML = `
<div class="header">User reception</div>
<div class="rym-reception">
    ${topItemHTML}
    ${otherItemsHTML}
</div>
        `;

        statsContainer.append(sectionHTML);
    }

    const checkReady = setInterval(() => {
        if ($('#chart_div').length && $('script:contains("drawChart1")').length) {
            clearInterval(checkReady);
            initUserReception();
        }
    }, 500);

    setTimeout(() => {
        clearInterval(checkReady);
        if ($('.rym-reception').length === 0) {
            initUserReception();
        }
    }, 5000);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址