ch_th

극장모드

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         ch_th
// @namespace    ch_th
// @version      0.0.1
// @description  극장모드
// @author       lc2122
// @match        https://chzzk.naver.com/*
// @match        https://lolcast.web.app/*
// @match        https://lolcast.kr/*

// ==/UserScript==

(function () {
    'use strict';
    let debug = false;

    let url = document.location.href;

    // 최상위 창(일반 치지직 시청)일 경우 스크립트 종료, 임베드(iframe) 환경에서만 실행
    let isTopWindow = window.self === window.top;
    if (isTopWindow) {
        return;
    }

    if (debug) console.log("chzzk embed", url);

    function waitForElement(selector, callback) {
        const existingElement = document.querySelector(selector);

        if (existingElement) {
            callback(existingElement);
        } else {
            const observer = new MutationObserver((mutationsList) => {
                const targetElement = document.querySelector(selector);
                if (targetElement) {
                    observer.disconnect();
                    callback(targetElement);
                }
            });

            observer.observe(document.documentElement, {
                childList: true,
                subtree: true,
            });
        }
    }

    let player = undefined;
    let handleVideoReadyFired = false;

    let handleVideoReady = function(){
        if (handleVideoReadyFired) return;
        handleVideoReadyFired = true;
        let viewmode_buttons = document.querySelectorAll(".pzp-pc__viewmode-button");
        if(viewmode_buttons.length == 1){
            viewmode_buttons[0].click();
        }
        else{
            // 치즈나이프와의 충돌 방지
            for (let i = 0; i < viewmode_buttons.length; i++) {
                let button = viewmode_buttons[i];
                if (button.getAttribute('aria-label') === '넓은 화면') {
                    button.click();
                    break;
                }
            }
        }

        // 채팅창 닫기 버튼 클릭
        let chatCloseButton = document.querySelector('[class^="live_chatting_header_button__"]');
        if (chatCloseButton) {
            chatCloseButton.click();
        }
    };

    waitForElement("video.webplayer-internal-video", function (node) {
        if (debug) console.log("found video player", node);
        player = node;
        if (player.readyState >= 2) {
            handleVideoReady();
        } else {
            player.addEventListener('loadedmetadata', function once() {
                player.removeEventListener('loadedmetadata', once);
                handleVideoReady();
            });
        }
        player.muted = true; // 비디오 음소거
    });

})();