TECHDOG 1-7 Re-numbering

a script to show techdog tracks like 1-1, 2-7, 6-11 on bandcamp

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         TECHDOG 1-7 Re-numbering
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  a script to show techdog tracks like 1-1, 2-7, 6-11 on bandcamp
// @author       CiNoP
// @license      MIT
// @match        https://patriciataxxon.bandcamp.com/album/techdog-1-7
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function renumber() {
        const tracks = document.querySelectorAll('.track_number');
        tracks.forEach((div, index) => {
            const globalNum = index + 1;
            const n = Math.ceil(globalNum / 11);
            const localNum = globalNum - 11 * (n - 1);
            const newText = `${n}-${localNum}.`;
            
            if (div.textContent !== newText) {
                div.textContent = newText;
                
                div.style.whiteSpace = 'nowrap';
                
                const parentCell = div.closest('.track-number-col');
                if (parentCell) {
                    parentCell.style.width = '45px';
                }
            }
        });
    }

    renumber();
    const observer = new MutationObserver(renumber);
    observer.observe(document.body, { childList: true, subtree: true });
})();