YouTube - Custom Default Settings

hide short, annotation, ad, liveChat, etc.

2025-01-06 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         YouTube - Custom Default Settings
// @name:en      YouTube - Custom Default Settings
// @name:ja      YouTube - 初期設定の変更
// @namespace    http://tampermonkey.net/
// @version      2025-01-07
// @description  hide short, annotation, ad, liveChat, etc.
// @description:en hide short, annotation, ad, liveChat, etc.
// @description:ja 画質 次の動画への秒数 文字起こしの有無 ライブチャットの有無などの変更
// @author       ぐらんぴ
// @match        https://www.youtube.com/*
// @icon         https://www.youtube.com/favicon.ico
// @grant        GM_addStyle
// @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: '720', /* 144, 240, 360, 480, 720, 1080 */ },
    { name: 'loop',          default: 'on', /* on or off */ },
    { name: 'shuffle',       default: 'on', /* on or off */ },
    // search
    { name: 'short',         default: 'hide', /* show or hide */ },
    // promo, ad
    { name: 'promo', default: 'hide', /* show or hide */ }, // testing
    { name: 'ad', default: 'hide', /* show or hide */ }, // testing
];
///-----------------------------------------------------------------------------------///
document.addEventListener('yt-page-data-fetched', e =>{
    let res = e.detail.pageData.response
    console.log(e.detail);
    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
            if(s.name == 'loop' && s.default == 'on' && e.detail.pageData.response.contents.twoColumnWatchNextResults.playlist){
                const loopId = setInterval(()=>{
                    if(document.querySelector("[aria-label='Loop playlist']")){
                        clearInterval(loopId);
                        document.querySelector("[aria-label='Loop playlist']").click();
                    }
                },1000);
            }
            if(s.name == 'shuffle' && s.default == 'on' && e.detail.pageData.response.contents.twoColumnWatchNextResults.playlist){
                const shuffleId = setInterval(()=>{
                    if(document.querySelector("[aria-label='Shuffle playlist']").getAttribute("aria-pressed") == 'false'){
                        clearInterval(shuffleId);
                        document.querySelector("[aria-label='Shuffle playlist']").click();
                    }
                },1000);
            }
            // search
            if(s.name == 'short' && s.default == 'hide'){
                // page: "browse" - top, "search"
                GM_addStyle(`
                ytd-reel-shelf-renderer {
                display: none;
                }

                ytd-rich-shelf-renderer {
                display: none;
                }`)
            }
            // promo, ad
            if(s.name == 'promo' && s.default == 'hide') e.detail.pageData.playerResponse.messages[0].mealbarPromoRenderer = null;
            if(s.name == 'ad' && s.default == 'hide'){
                if(e.detail.pageData.page == "watch"){ // page: "watch"
                    e.detail.pageData.playerResponse.auxiliaryUi = null; // testing
                }
                GM_addStyle(`ytd-ad-slot-renderer {
                display: none;
                }`)
        }
        }catch(err){ //console.log(err)
        }
    });
});
/* page load function
document.addEventListener('yt-service-request-sent', e => {
    // console.log('loaded', e)
});
*/