YouTube Playlist Time

Adds a timestamp of all videos' time combined.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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.';
  }
});