Greasy Fork

Greasy Fork is available in English.

치지직 1080p 고정 + 광고 팝업 삭제 + 자동 재생

치지직 1080p 고정 및 광고 팝업 삭제, 각 기능 별도로 실행 후 종료

当前为 2024-11-04 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         치지직 1080p 고정 + 광고 팝업 삭제 + 자동 재생
// @namespace    http://tampermonkey.net/
// @version      1.0.2
// @description  치지직 1080p 고정 및 광고 팝업 삭제, 각 기능 별도로 실행 후 종료
// @match        *://chzzk.naver.com/*
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    let previousChannelId = null;
    let scriptRunning = false;

    // URL 변화를 감지하는 함수
    const detectChannelChange = () => {
        const currentUrl = window.location.href;
        const channelIdMatch = currentUrl.match(/live\/([a-f0-9]{32})/);
        const currentChannelId = channelIdMatch ? channelIdMatch[1] : null;

        if (currentChannelId && currentChannelId !== previousChannelId) {
            previousChannelId = currentChannelId;
            console.log("채널 변경 감지, 스크립트 재실행");
            if (!scriptRunning) {
                executeScripts();
            }
        }
    };

    // 주기적으로 URL 변경 확인 (5000ms마다 확인)
    setInterval(detectChannelChange, 5000);

    // 각 기능을 수행하는 스크립트 실행 함수
    function executeScripts() {
        scriptRunning = true;

        // 랜덤 지연 시간 생성 함수 (500ms ~ 1500ms 사이 랜덤)
        function getRandomDelay() {
            return Math.floor(Math.random() * 1000) + 500;
        }

        // 중복 실행 방지를 위한 플래그
        let qualitySet = false;
        let adRemoved = false;

        // 모든 작업이 완료되었는지 확인하고 스크립트를 종료하는 함수
        function checkAndTerminate() {
            if (qualitySet && adRemoved) {
                console.log("모든 작업 완료, 스크립트 종료");
                scriptRunning = false;
                previousChannelId = null; // 이전 채널 ID 초기화하여 재실행 방지
                return true;
            }
            return false;
        }

        // 품질 설정을 1080p로 고정하는 코드
        const qualityInterval = setInterval(() => {
            if (qualitySet) {
                clearInterval(qualityInterval); // 플래그가 true이면 인터벌 종료
                return;
            }

            const qualityElement = document.querySelector(
                `.pzp-pc-setting-quality-pane__list-container > li:first-child:not(.pzp-pc-ui-setting-item--checked)`
            );
            if (qualityElement) {
                setTimeout(() => {
                    qualityElement.click();
                    console.log("1080p 고정");
                    qualitySet = true; // 작업 완료 플래그 설정
                    clearInterval(qualityInterval);
                    console.log("품질 설정 인터벌 종료");
                    if (checkAndTerminate()) {
                        return;
                    }
                }, getRandomDelay());
            }
        }, 500);

        // 광고 팝업 제거 코드
        const adInterval = setInterval(() => {
            if (adRemoved) {
                clearInterval(adInterval); // 플래그가 true이면 인터벌 종료
                return;
            }

            const adbb = document.querySelector(`[class^="ad_block_title"]`);
            if (adbb) {
                setTimeout(() => {
                    const closeButton = document.querySelector(`[class^=popup_cell] > button`);
                    if (closeButton) {
                        closeButton.click();
                        console.log("Remove adblock");
                        adRemoved = true; // 작업 완료 플래그 설정
                        clearInterval(adInterval); // 광고 팝업을 찾으면 인터벌을 종료하여 한 번만 실행
                        if (checkAndTerminate()) {
                            return;
                        }
                    }
                }, getRandomDelay());
            }
        }, 500);
    }

    // 처음 페이지 로드 시 스크립트 실행
    if (!scriptRunning) {
        executeScripts();
    }
})();