Youtube Playlist Total Duration

Add the total duration of a YouTube Playlist

当前为 2021-01-18 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Youtube Playlist Total Duration
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Add the total duration of a YouTube Playlist
// @author       Benoit Durand
// @match        *://www.youtube.com/playlist?list=*
// @grant        none
// ==/UserScript==

function addPlaylistDuration() {

  var el = document.getElementsByClassName("style-scope ytd-thumbnail-overlay-time-status-renderer");
  var nb_video = document.getElementById("stats").getElementsByClassName("style-scope yt-formatted-string")[0].innerHTML;

  if (el.length == 2 * nb_video) {

    var s = 0;

    var eq_sec = [3600, 60, 1];

    for (var i = 0; i < el.length; i++) {

      if (el[i].tagName == "SPAN") {

        var time = el[i].innerHTML.replace(/\n/gi, "").split(":");

        var selec = eq_sec.slice(-time.length);

        for (var j = 0; j < time.length; j++){
            s = s + Number(time[j]) * selec[j];
        }
      }
    }

    var nb_hour = Math.trunc(s / 3600);
    s = s%3600;
    var nb_min = Math.trunc(s / 60);
    s = s%60;
    var nb_sec = s;

    var final_string = "\n Total Duration : " + nb_hour + ":" + nb_min.toString().padStart(2, '0') + ":" + nb_sec.toString().padStart(2, '0') ;

    document.getElementById("description").appendChild(document.createTextNode(final_string));
  } else {

    setTimeout(addPlaylistDuration, 50); // try again in 50 milliseconds
  }
}

 addPlaylistDuration();