YouTube Millisecond Timer

Показывает время воспроизведения видео с миллисекундами на YouTube

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         YouTube Millisecond Timer
// @namespace    https://youtube.com/
// @version      1.0
// @description  Показывает время воспроизведения видео с миллисекундами на YouTube
// @author       christopher wayne
// @match        https://www.youtube.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    const waitForPlayer = setInterval(() => {
        const video = document.querySelector('video');
        const timeDisplay = document.querySelector('.ytp-time-current');

        if (video && timeDisplay) {
            clearInterval(waitForPlayer);
            addMillisecondDisplay(video, timeDisplay);
        }
    }, 500);

    function addMillisecondDisplay(video, originalDisplay) {
        const customDisplay = document.createElement('span');
        customDisplay.style.marginLeft = '10px';
        customDisplay.style.color = '#0ff';
        customDisplay.style.fontSize = '14px';
        customDisplay.style.fontFamily = 'monospace';

        originalDisplay.parentNode.appendChild(customDisplay);

        setInterval(() => {
            const time = video.currentTime;
            const minutes = Math.floor(time / 60);
            const seconds = Math.floor(time % 60);
            const milliseconds = Math.floor((time % 1) * 1000);
            const formatted = `${pad(minutes)}:${pad(seconds)}.${padMs(milliseconds)}`;
            customDisplay.textContent = formatted;
        }, 50);
    }

    function pad(n) {
        return n.toString().padStart(2, '0');
    }

    function padMs(ms) {
        return ms.toString().padStart(3, '0');
    }
})();