Chzzk script

자동 최고화질 설정, 광고 차단 팝업 삭제

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Chzzk script
// @namespace    http://tampermonkey.net/
// @version      1.0.0
// @description  자동 최고화질 설정, 광고 차단 팝업 삭제
// @author       author
// @match        *://*.chzzk.naver.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=chzzk.naver.com
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    const script = document.createElement('script');
    script.src = 'https://unpkg.com/[email protected]/dist/xhook.min.js';
    script.onload = function() {
        window.xhook.after((request, response) => {
            if (!response || !response.text) return;
            const url = request.url;

            if (url.includes("/live-detail") || /\/service\/v\d+\/videos\/\d+/.test(url)) {
                try {
                    const data = JSON.parse(response.text);
                    if (data && data.content && typeof data.content === "object") {
                        data.content.dab = false;
                        response.text = JSON.stringify(data);
                    }
                } catch (e) {
                }
            }
        });
    };
    document.head.appendChild(script);

    window.addEventListener('DOMContentLoaded', () => {
        let lastUrl = location.href;
        let qualityInterval = null;
        let playbackInterval = null;

        function handlePlaybackButton() {
            const playbackSwitchButton = document.querySelector('button.pzp-playback-switch');
            if (playbackSwitchButton) {
                const animateElement = playbackSwitchButton.querySelector('animate');
                if (!animateElement) {
                    playbackSwitchButton.click();
                    return false;
                }
            }
            if (playbackInterval) {
                clearInterval(playbackInterval);
                playbackInterval = null;
            }
            return true;
        }

        function selectHighestQuality() {
            const settingsButton = document.querySelector('button[class*="pzp-setting-button"]');
            if (!settingsButton) return false;

            settingsButton.click();

            setTimeout(() => {
                const qualityButton = document.querySelector('div[class*="pzp-pc-setting-intro-quality"]');
                if (!qualityButton) return;
                qualityButton.click();

                setTimeout(() => {
                    const qualityOptions = document.querySelectorAll('li[class*="quality-item"]');
                    let qualityOption = Array.from(qualityOptions).find(option => option.textContent.includes('1080')) ||
                                        Array.from(qualityOptions).find(option => option.textContent.includes('720'));

                    if (!qualityOption) return;

                    qualityOption.focus();
                    const enterEvent = new KeyboardEvent('keydown', {
                        bubbles: true,
                        cancelable: true,
                        key: 'Enter',
                        code: 'Enter',
                        keyCode: 13,
                        which: 13
                    });

                    if (!playbackInterval) {
                        playbackInterval = setInterval(handlePlaybackButton, 50);
                    }

                    qualityOption.dispatchEvent(enterEvent);
                }, 50);
            }, 50);

            if (qualityInterval) {
                clearInterval(qualityInterval);
                qualityInterval = null;
            }
            return true;
        }

        function startQualityCheck() {
            if (!qualityInterval) {
                qualityInterval = setInterval(selectHighestQuality, 50);
            }
        }

        document.addEventListener('click', () => {
            setTimeout(() => {
                if (location.href !== lastUrl) {
                    lastUrl = location.href;
                    if (lastUrl.includes('/live/') || lastUrl.includes('/video/')) {
                        startQualityCheck();
                    }
                }
            }, 100);
        });

        if (location.href.includes('/live/') || location.href.includes('/video/')) {
            startQualityCheck();
        }
    });
})();