치지직 1080p 해상도 고정 + 광고 차단 팝업 제거

해상도를 자동으로 1080으로 변환하고, 광고 차단 팝업을 제거합니다.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name          치지직 1080p 해상도 고정 + 광고 차단 팝업 제거
// @namespace     치지직 1080p 해상도 고정 + 광고 차단 팝업 제거
// @match         *://chzzk.naver.com/*
// @version       0.1
// @description   해상도를 자동으로 1080으로 변환하고, 광고 차단 팝업을 제거합니다.
// @icon          https://www.google.com/s2/favicons?sz=256&domain_url=chzzk.naver.com
// @author        mickey90427 <[email protected]>
// @grant         none
// @license       MIT
// ==/UserScript==

(function() {
    'use strict';

    // 팝업 제거 함수
    function removePopup() {
        const popup = document.querySelector('.popup_dimmed__zs78t');
        if (popup) {
            popup.remove();
        }
    }

    // 해상도 설정 함수
    function setResolution() {
        const settingsButton = document.querySelector('.pzp-pc-setting-button');

        if (settingsButton) {
            settingsButton.click();

            setTimeout(() => {
                const qualityMenu = document.querySelector('.pzp-pc-setting-intro-quality');
                if (qualityMenu) {
                    qualityMenu.click();

                    setTimeout(() => {
                        const options = document.querySelectorAll('.pzp-pc-ui-setting-quality-item');
                        const option1080p = Array.from(options).find(option => option.textContent.includes('1080p'));
                        const option720p = Array.from(options).find(option => option.textContent.includes('720p'));

                        if (option1080p && !option1080p.classList.contains('pzp-pc-ui-setting-item--checked')) {
                            option1080p.click();
                        } else if (option720p && !option720p.classList.contains('pzp-pc-ui-setting-item--checked')) {
                            option720p.click();
                        }
                    }, 500);
                }
            }, 500);
        }
    }

    // 스크롤 오류 수정 함수
    function fixScrollIssue() {
        document.body.style.overflow = 'auto';
        document.documentElement.style.overflow = 'auto';

        // `position: fixed` 속성 제거
        document.body.style.position = '';
        document.documentElement.style.position = '';

        // `height` 속성 재설정
        document.body.style.height = 'auto';
        document.documentElement.style.height = 'auto';
    }

    // URL 변화 감지하여 해상도 및 스크롤 재설정
    let lastUrl = location.href;
    setInterval(() => {
        if (location.href !== lastUrl) {
            lastUrl = location.href;

            if (location.href === 'https://chzzk.naver.com/lives') {
                setTimeout(fixScrollIssue, 500);
            } else {
                setTimeout(setResolution, 1000);
            }
        }
    }, 1000);

    // 페이지 처음 로드 시 해상도 설정 및 스크롤 문제 확인
    window.addEventListener('load', () => {
        if (location.href === 'https://chzzk.naver.com/lives') {
            fixScrollIssue();
        } else {
            setTimeout(setResolution, 1000);
        }
    });

    // MutationObserver를 사용하여 DOM 변화를 감지하여 팝업 제거
    const observer = new MutationObserver(removePopup);
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

    // 초기 로딩 시 팝업이 있을 경우 제거
    removePopup();
})();