YouTube Video Duration Checker

Shows the duration of YouTube videos on mobile browsers.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         YouTube Video Duration Checker
// @namespace    https://greasyfork.org/en/users/670188-hacker09?sort=daily_installs
// @version      2
// @description  Shows the duration of YouTube videos on mobile browsers.
// @author       hacker09
// @match        https://*.youtube.com/embed/*
// @icon         https://www.youtube.com/s/desktop/03f86491/img/favicon.ico
// @run-at       document-end
// @grant        none
// ==/UserScript==

(function() {
  'use strict';
  document.querySelector(".notranslate").style.display = 'unset'; //Display the time
  document.querySelector('.video-stream').addEventListener('timeupdate', function() { //When the YT video is playing
    var currentSecs = Math.floor(document.querySelector('.video-stream').currentTime % 60); //Create a variable to hold the current secs
    var totalSecs = Math.floor(document.querySelector('.video-stream').duration % 60); //Create a variable to hold the total mins
    document.querySelector(".ytp-time-current").innerText = `${Math.floor(document.querySelector('.video-stream').currentTime / 60)}:${currentSecs < 10 ? '0' + currentSecs : currentSecs}`;
    document.querySelector(".ytp-time-duration").innerText = `${Math.floor(document.querySelector('.video-stream').duration / 60)}:${(/^\d$/.test(totalSecs)) ? '0' + totalSecs : totalSecs}`;
  }); //Update the content of the time display element
})();