Chzzk script

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

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

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

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

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