Chzzk script

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

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

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