Chzzk script

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

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

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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();
        }
    });
})();