ISRC Hunt: Highlight ISRC matches and differences

Highlights matching ISRCs in green and non-matches red

当前为 2025-05-27 提交的版本,查看 最新版本

// ==UserScript==
// @name         ISRC Hunt: Highlight ISRC matches and differences
// @namespace    https://musicbrainz.org/user/chaban
// @version      1.1.1
// @description  Highlights matching ISRCs in green and non-matches red
// @tag          ai-created
// @author       chaban
// @license      MIT
// @match        *://isrchunt.com/spotify/importisrc
// @match        *://isrchunt.com/deezer/importisrc
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const table = document.querySelector('.table');
    if (!table) {
        return;
    }

    const rows = table.querySelectorAll('tr');

    for (let i = 1; i < rows.length; i++) {
        const row = rows[i];
        const spotifyIsrcCell = row.querySelector('td:nth-child(4)');
        const mbIsrcCell = row.querySelector('td:nth-child(7)');

        if (spotifyIsrcCell && mbIsrcCell) {
            const spotifyIsrcs = spotifyIsrcCell.textContent.trim().split(',').map(isrc => isrc.trim().toLowerCase());
            const mbIsrcsLowercased = mbIsrcCell.textContent.trim().split(',').map(isrc => isrc.trim().toLowerCase());
            const mbIsrcsSetLowercased = new Set(mbIsrcsLowercased);
            const originalMbIsrcs = mbIsrcCell.textContent.trim().split(',').map(isrc => isrc.trim());

            let spotifyHtml = '';
            spotifyIsrcs.forEach((sIsrcLower, index) => {
                const originalSIsrc = spotifyIsrcCell.textContent.trim().split(',')[index].trim();
                const bgColor = mbIsrcsSetLowercased.has(sIsrcLower) ? 'lightgreen' : 'salmon';
                spotifyHtml += `<span style="background-color: ${bgColor};">${originalSIsrc}</span>`;
                if (index < spotifyIsrcs.length - 1) {
                    spotifyHtml += ', ';
                }
            });
            spotifyIsrcCell.innerHTML = spotifyHtml;

            const spotifyIsrcsSetLowercased = new Set(spotifyIsrcs);
            let mbHtml = '';
            originalMbIsrcs.forEach((originalMIsrc, index) => {
                const mIsrcLower = mbIsrcsLowercased[index];
                const bgColor = spotifyIsrcsSetLowercased.has(mIsrcLower) ? 'lightgreen' : 'salmon';
                mbHtml += `<span style="background-color: ${bgColor};">${originalMIsrc}</span>`;
                if (index < originalMbIsrcs.length - 1) {
                    mbHtml += ', ';
                }
            });
            mbIsrcCell.innerHTML = mbHtml;
        }
    }
})();