YouTube - Custom Default Settings

live chat, transcript, auto play count

目前為 2024-12-29 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         YouTube - Custom Default Settings
// @name:en      YouTube - Custom Default Settings
// @name:ja      YouTube - デフォルト設定の変更
// @namespace    http://tampermonkey.net/
// @version      2024-12-29
// @description  live chat, transcript, auto play count
// @description:en live chat, transcript, auto play count
// @description:ja デフォルト設定の変更
// @author       ぐらんぴ
// @match        https://www.youtube.com/*
// @icon         https://www.youtube.com/favicon.ico
// @grant        none
// @license      MIT
// ==/UserScript==

const settings = [
    // page: "watch"
    { name: 'liveChat',      default: 'hide', /* show or hide */ },
    { name: 'transcript',    default: 'hide', /* show or hide */ },
    { name: 'autoPlayCount', default: '0', /* 0 or more */ },
    { name: 'annotation',    default: 'hide', /* show or hide */ },
    { name: 'quality',       default: '1080', /* 144, 240, 360, 480, 720, 1080 */ },
    // // page: "all"
    { name: 'Promo', default: 'hide', /* show or hide */ },
];
document.addEventListener('yt-page-data-fetched', e =>{
    let res = e.detail.pageData.response
    // console.log(e.detail);
    console.log(e.detail.pageData)
    settings.forEach(s =>{
        try{
            // page: "watch"
            if(s.name == 'liveChat' && s.default == 'hide') res.contents.twoColumnWatchNextResults.conversationBar.liveChatRenderer.initialDisplayState = 'LIVE_CHAT_DISPLAY_STATE_COLLAPSED';
            if(s.name == 'transcript' && s.default == 'show'){
                let engagementPanels = res.engagementPanels
                engagementPanels.forEach(i =>{
                    if(i.engagementPanelSectionListRenderer.targetId == 'engagement-panel-searchable-transcript') i.engagementPanelSectionListRenderer.visibility = 'ENGAGEMENT_PANEL_VISIBILITY_EXPANDED';

                });
            }
            if(s.name == 'autoPlayCount'){
                res.playerOverlays.playerOverlayRenderer.autoplay.playerOverlayAutoplayRenderer.countDownSecs = s.default
                res.playerOverlays.playerOverlayRenderer.autoplay.playerOverlayAutoplayRenderer.countDownSecsForFullscreen = s.default
            }
            if(s.name == 'annotation' && s.default == 'hide') document.querySelector(".annotation.annotation-type-custom").style.display = "none" // https://i.ytimg.com/an/
            if(s.name == 'quality'){
                for (let i = 0; i < localStorage.length; i++) {
                    let key = localStorage.key(i);
                    if (key === "yt-player-quality") {
                        let data = localStorage.getItem(key);
                        // console.log(data);

                        let obj = JSON.parse(data);
                        let innerData = JSON.parse(obj.data);

                        innerData.quality = s.default;
                        obj.data = JSON.stringify(innerData);

                        let newData = JSON.stringify(obj);
                        // console.log(newData);

                        localStorage.setItem(key, newData);
                    }
                }

            }
            // playList
            // page: "all"
            if(s.name == 'promo' && s.default == 'hide'){
                // promo
                e.detail.pageData.playerResponse.messages[0].mealbarPromoRenderer.isVisible = false;
            }
        }catch{}
    });
});