Watch9 Reconstruct

Restores the classic Watch page layout from before 2019

目前為 2022-07-22 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Watch9 Reconstruct
// @version      1.1.3
// @description  Restores the classic Watch page layout from before 2019
// @author       Aubrey
// @match        https://www.youtube.com/*
// @license      MIT
// @icon         https://www.google.com/s2/favicons?domain=youtube.com
// @grant        none
// @run-at       document-start
// @namespace    aubymori
// ==/UserScript==
async function waitForElm(q) {
    while (document.querySelector(q) == null) {
        await new Promise(r => requestAnimationFrame(r));
    };
    return document.querySelector(q);
};

const w9rStyle = document.createElement("style");
w9rStyle.innerHTML = `
    #w9r-sub-count {
        opacity: .8;
        margin-left: 6px;
    }

    #info-strings.ytd-video-primary-info-renderer,
    #owner-sub-count {
        display: none !important;
    }

    ytd-button-renderer.style-primary #w9r-sub-count {
        display: none;
    }
`;
document.getElementsByTagName("head")[0].appendChild(w9rStyle);

document.addEventListener("yt-page-data-updated", async function() {
    var pubDate = await waitForElm("ytd-video-primary-info-renderer");
    const pubDatePnt = pubDate.data.dateText.simpleText;
    function fixPubDate(date) {
        if (/(Premier)|(Stream)|(Start)/.test(date)) {
            return date;
        } else {
            return "Published on " + date;
        }
    }
    var subCnt = await waitForElm("ytd-video-secondary-info-renderer");
    const subCntPnt = subCnt.data.owner.videoOwnerRenderer.subscriberCountText.simpleText;
    function fixSubCnt(cnt) {
        return cnt.replace(/( subscribers)|( subscriber)/, "").replace("No", "0");
    }
    var subBtn = await waitForElm("#subscribe-button tp-yt-paper-button");
    var pubDateElm = await waitForElm(".date.ytd-video-secondary-info-renderer");
    var viewCount = await waitForElm("ytd-video-view-count-renderer");
    if (document.querySelector("#w9r-sub-count") == null) {
        var w9rSubCount = document.createElement("yt-formatted-string");
        w9rSubCount.text = {runs:[{text: subCntPnt.replace(/( subscribers)|( subscriber)/, "").replace("No", "0")}]};
        w9rSubCount.id = "w9r-sub-count";
        subBtn.querySelector("yt-formatted-string").insertAdjacentElement("afterEnd", w9rSubCount)
    } else {
        document.querySelector("#w9r-sub-count").text = {simpleText:fixSubCnt(subCntPnt)};//{runs:[{text: fixSubCnt(subCntPnt)}]};
    };

    viewCount.removeAttribute("small");
    pubDateElm.innerHTML = fixPubDate(pubDatePnt);
});