Greasy Fork

Greasy Fork is available in English.

Colorful Repertoire With Music quality

28/09/2024, 00:38:02

当前为 2024-09-30 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Colorful Repertoire With Music quality
// @namespace   Violentmonkey Scripts
// @match       https://*.popmundo.com/World/Popmundo.aspx/Artist/Repertoire/*
// @grant       GM_setValue
// @grant       GM_getValue
// @license     M.I.T
// @version     1.1
// @description 28/09/2024, 00:38:02
// ==/UserScript==

const currentUrl = window.location.href;
const bandId = currentUrl.split('/').pop();
const urlDomain = window.location.hostname;

jQuery(document).ready(function () {
    // Create a div for color pickers
    const colorPickerDiv = jQuery('<div>', { class: 'box', css: { marginBottom: '10px', padding: '10px', border: '1px solid #ccc' } });
    const heading = jQuery('<h2>').text('Configuração das Cores').appendTo(colorPickerDiv);

    // Create color pickers
    const propriaColorPickerLabel = jQuery('<label>').text('Cor para banda própria: ').appendTo(colorPickerDiv);
    const propriaColorPicker = jQuery('<input>', { type: 'color', value: GM_getValue('propriaColor', '#008000') }).appendTo(propriaColorPickerLabel);

    const naoPropriaColorPickerLabel = jQuery('<label>').text(' Cor para banda não própria: ').appendTo(colorPickerDiv);
    const naoPropriaColorPicker = jQuery('<input>', { type: 'color', value: GM_getValue('naoPropriaColor', '#FFFF00') }).appendTo(naoPropriaColorPickerLabel);

    // Save the selected colors in GM storage when changed
    propriaColorPicker.on('change', function () {
        GM_setValue('propriaColor', propriaColorPicker.val());
    });

    naoPropriaColorPicker.on('change', function () {
        GM_setValue('naoPropriaColor', naoPropriaColorPicker.val());
    });

    // Insert the color picker div above the table
    jQuery('#tablesongs').before(colorPickerDiv);

    // Cria um iframe único que será reutilizado para cada link e o oculta
    const iframe = jQuery('<iframe>', {
        id: 'songIframe',
        width: '0px',
        height: '0px',
        css: { display: 'none' } // Deixa o iframe oculto inicialmente
    }).appendTo('#ppm-wrapper');

    // Seleciona todos os links da tabela
    const links = jQuery('#tablesongs tbody tr td a');
    let currentIndex = 0;

    // Função para processar um link
    function processLink() {
        if (currentIndex >= links.length) {
            console.log('Processamento concluído para todos os links.');
            iframe.remove(); // Remove o iframe após concluir o processamento de todos os links
            return;
        }

        const currentLink = jQuery(links[currentIndex]);
        const originalText = currentLink.text();
        const currentLinkHref = currentLink.attr('href');
        const linkFormatted = "https://" + urlDomain + currentLinkHref;
        let notaMelodia = 0;
        let notaLetra = 0;
        let bandaPropria = false;

        // Atualiza o iframe com o novo link
        iframe.attr('src', linkFormatted);

        iframe.off('load').on('load', function () {
            const iframeContent = iframe.contents();
            let div1stBox = iframeContent.find('div.box').first();
            const bandHref = div1stBox.find('a[href^="/World/Popmundo.aspx/Artist/"]').attr('href');

            if (bandHref) {
                const bandIdFromHref = bandHref.split('/').pop();
                if (bandIdFromHref === bandId) {
                    bandaPropria = true;
                }
            }

            let div2ndBox = iframeContent.find('div.box').eq(1);
            const melodiaTitle = div2ndBox.find('p a').eq(0).attr('title');
            const letraTitle = div2ndBox.find('p a').eq(1).attr('title');

            if (melodiaTitle && letraTitle) {
                notaMelodia = melodiaTitle.split('/')[0];
                notaLetra = letraTitle.split('/')[0];

                console.log(`Link ${currentIndex + 1} - Nota da Melodia: ${notaMelodia}`);
                console.log(`Link ${currentIndex + 1} - Nota da Letra: ${notaLetra}`);

                let newText = `${originalText} (${notaMelodia}/${notaLetra})`;
                currentLink.text(newText);

                // Get saved colors from GM storage
                const propriaColor = GM_getValue('propriaColor', '#008000'); // Default green
                const naoPropriaColor = GM_getValue('naoPropriaColor', '#FFFF00'); // Default yellow

                if (bandaPropria) {
                    currentLink.css({ 'color': propriaColor });
                } else {
                    currentLink.css({ 'color': naoPropriaColor });
                }
            } else {
                console.error('Não foi possível encontrar os títulos para as notas da melodia e da letra.');
            }

            // Avança para o próximo link
            currentIndex++;
            processLink();
        });
    }

    // Inicia o processamento do primeiro link
    processLink();
});