YouTube Title Duration

puts the duration in the title, works with sponsorblock

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         YouTube Title Duration
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  puts the duration in the title, works with sponsorblock
// @author       EntranceJew
// @match        https://www.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant        none
// @license      MIT
// ==/UserScript==
//debugger;


(function() {
    'use strict';

    var wait = 500
    var observer = new MutationObserver(resetTimer);
    var timer = setTimeout(action, wait, observer); // wait for the page to stay still for 3 seconds
    observer.observe(document, {childList: true, attributes: true, characterData: true, subtree: true});

    function isEmpty(string) {
        return typeof string === 'string' && string.length === 0;
    }

    // reset timer every time something changes
    function resetTimer(changes, observer) {
        clearTimeout(timer);
        timer = setTimeout(action, wait, observer);
    }

    function bashIt(selector) {
        let target = document.querySelector(selector);
        if(target && !isEmpty(target.textContent)) {
            var title = document.querySelector("title").textContent;
            var x = target.textContent.replace(/[\( \)]+/g, '');
            document.querySelector("title").textContent = "[" + x + "] " + title;
            return true;
        }
        return false;
    }

    function action(observer) {
        if(bashIt("#sponsorBlockDurationAfterSkips")) {
            observer.disconnect();
            return;
        }
        if(bashIt("ytd-player .ytp-time-duration")) {
            observer.disconnect();
            return;
        }
    }
})();