Bandcamp Total Duration

Displays total length of albums on bandcamp.com

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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
    }
}