YouTube Playlist Time

Adds a timestamp of all videos' time combined.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        YouTube Playlist Time
// @namespace   YouTube Playlist Time
// @description Adds a timestamp of all videos' time combined.
// @author      kriscross07
// @include     *.youtube.com/*
// @version     1.6
// @grant       none
// @run-at      document-start
// ==/UserScript==

addEventListener('DOMContentLoaded',function(){
  var time,mins=0,interval=true;

  addControls();
  interval&&setInterval(addControls,100);
  
  function addControls(){
    if(time&&document.contains(time)||!/^https:\/\/www.youtube.com\/playlist/.test(location.href))return;
    
    time=document.createElement('span');
    
    time.onclick=updateTime;
    time.title=time.innerHTML='Click to update time.';
    
    document.querySelector('.playlist-actions').appendChild(time);
    updateTime();
  }
  function updateTime(){
    var stamps=document.querySelectorAll('.timestamp>span');
    mins=0;
    for(var i=0;i<stamps.length;i++){
      var min=stamps[i].innerHTML.split(':');
      mins+=min[1]>=30?parseInt(min[0])+1:parseInt(min[0]);
    }
    time.innerHTML=mins>60?(mins/60).toFixed(1)+' hours.':mins+' minutes.';
  }
});