YouTube Detailed Timecode

Displays a time in seconds to 3 decimal places when paused.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         YouTube Detailed Timecode
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Displays a time in seconds to 3 decimal places when paused.
// @author       Charlie Laabs
// @match        https://*.youtube.com/*
// @match        http://*.youtube.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    console.log('Running YTDT');
    var ytPlayer;
    var ytPlayerUnwrapped;
    var detailedTime = document.createElement('span');
    var playerInitialized = false;

    function getElements() {
        ytPlayer = document.getElementById("movie_player") || document.getElementsByClassName("html5-video-player")[0];
        ytPlayerUnwrapped = ytPlayer.wrappedJSObject;
        if (ytPlayer)
        {
            detailedTime.innerHTML = "";
            ytPlayer.addEventListener("onStateChange", playerChanged, true );
            document.addEventListener("keyup", keyUp, true );
        }
    }

    function playerStarted()
    {
        var timeDisp = ytPlayer.getElementsByClassName("ytp-time-display")[0];
        detailedTime.className = 'us-detailed-time';
        detailedTime.style.paddingLeft = '5px';
        timeDisp.appendChild(detailedTime);
        playerInitialized = true;

    }

    function playerChanged(state)
    {
        //console.log("stateChanged: ", state);
        if (state != -1 && !playerInitialized ) {
            playerStarted();
        }
        if (state == 2) {
            detailedTime.innerHTML = '| ' + ytPlayerUnwrapped.getCurrentTime().toFixed(3);
        }

    }

    function keyUp(e)
    {
        //console.log('keyUp:', e);
        if (e.keyCode == 188 || e.keyCode == 190) {
            detailedTime.innerHTML = '| ' + ytPlayerUnwrapped.getCurrentTime().toFixed(3);
        }
    }
    getElements(); //for embedded videos
    document.addEventListener("yt-navigate-finish", getElements, true ); //for YouTube


})();