Bandcamp Total Duration

Displays total length of albums on bandcamp.com

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name     Bandcamp Total Duration
// @version  1
// @description Displays total length of albums on bandcamp.com
// @grant    none
// @include https://*.bandcamp.com/album/*
// @include https://music.businesscasual.biz/album/*
// @include https://listen.20buckspin.com/album/*
// @namespace https://greasyfork.org/users/708837
// ==/UserScript==

//this script will not run on custom bandcamp domains unless they are added to the above @include list

var allDurations, totalDuration, totalSeconds, totalMinutes, description, releaseDate;


//find all instances of song lengths
allDurations = document.evaluate(
    "//span[@class='time secondaryText']",
    document,
    null,
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
    null);


//parse the times and add them
totalSeconds = 0;
totalMinutes = 0;
for (var i = 0; i < allDurations.snapshotLength; i++) {
    totalMinutes += Number(allDurations.snapshotItem(i).firstChild.data.trim().split(":")[0]);
    totalSeconds += Number(allDurations.snapshotItem(i).firstChild.data.trim().split(":")[1]);
}


//convert to total time
finalSeconds = totalSeconds % 60
finalMinutes = totalMinutes + Math.floor(totalSeconds / 60);
totalDuration = finalMinutes + ':' + finalSeconds;
//console.log('Total Duration: ' + totalDuration);


//add as first line in description box
description = document.getElementsByClassName('tralbumData tralbum-about');
if (description.length) {
    description[0].innerText = 'Length: ' + totalDuration + '\n\n' + description[0].innerText;
}

//if no description box exists, add as line above release date
else {
    releaseDate = document.getElementsByClassName('tralbumData tralbum-credits');
    console.log(releaseDate[0].innerText);
    if (releaseDate.length) {
        releaseDate[0].innerText = 'Length: ' + totalDuration + '\n\n' + releaseDate[0].innerText
    }
}