CC163FullScreen

CC直播网页全屏,去掉播放器野外的元素

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         CC163FullScreen
// @namespace    https://greasyfork.org/zh-CN/users/135090
// @version      1.5.8
// @description  CC直播网页全屏,去掉播放器野外的元素
// @author       You
// @match        https://cc.163.com/1*
// @match        https://cc.163.com/2*
// @match        https://cc.163.com/3*
// @match        https://cc.163.com/4*
// @match        https://cc.163.com/5*
// @match        https://cc.163.com/6*
// @match        https://cc.163.com/7*
// @match        https://cc.163.com/8*
// @match        https://cc.163.com/9*
// @match        https://cc.163.com/live/channel/*
// @run-at       document-end
// ==/UserScript==

/* global __NEXT_DATA__, Player, HlsPlayer */
'use strict';
setTimeout(function() {
    if (location.pathname.includes("channel")) {
        const loadCSS = (href) => {
            if (!document.querySelector(`link[href="${href}"]`)) {
                const link = document.createElement('link');
                link.rel = 'stylesheet';
                link.href = href;
                document.head.appendChild(link);
            }
        };
        
        // 加载CSS样式
        loadCSS('https://cdn.jsdelivr.net/npm/xgplayer@latest/dist/index.min.css');
        // 动态加载XGPlayer
        const scripts = [
            'https://cdn.jsdelivr.net/npm/xgplayer@latest/dist/index.min.js',
            'https://cdn.jsdelivr.net/npm/xgplayer-hls@latest/dist/index.min.js'
        ];
        
        scripts.forEach(src => {
            if (!document.querySelector(`script[src="${src}"]`)) {
                const script = document.createElement('script');
                script.src = src;
                script.async = false;
                document.body.appendChild(script);
            }
        });
        const rdata = JSON.parse(document.body.querySelector("pre").textContent);
        let data = rdata?.data[0];
        // 获取直播数据{
        if (data?.is_audiolive === 1) {
                document.body.innerHTML = "<h1>音频直播,暂不支持</h1>";
                return;
        }
        setTimeout(() => initPlayer(data), 500);
        

        function initPlayer(data) {
            document.body.replaceChildren();
            document.body.style.background="#EAEAEA";
            document.title = data.nickname;
            
            // 创建播放器容器
            const container = document.createElement('div');
            container.id = 'box';
            container.style.cssText = "margin: 0 auto;;height:auto;width:88vw;background:#AAA;";
            const xgp = document.createElement('div');
            xgp.id = 'xgplayer';
            container.appendChild(xgp);
            // 创建直播间信息
            const info = document.createElement('div');
            info.style.cssText = `
                position: absolute;
                bottom: 10px;
                left: 10px;
                color: white;
                background: rgba(0,0,0,0.5);
                padding: 0;
                z-index: 999;
                border-radius: 4px;
                font-size: 16px;
            `;
            info.innerHTML = `
                <a href="https://cc.163.com/${data.ccid}" 
                   style="color:#fff;text-decoration:none">
                    ${data.nickname} 的直播间
                </a>
            `;
            container.appendChild(info);
            document.body.appendChild(container);

            // 初始化XGPlayer
            new Player({
                id: 'xgplayer',
                url: data.sharefile,
                poster: data.cover,
                isLive: true,
                autoplay: true,
                fluid: true,
                volume: 1.0,
                lang: 'zh-cn',
                cssFullscreen: true,
                plugins: [HlsPlayer]
            });
        }
    } else {
        const livedata=__NEXT_DATA__?.props?.pageProps?.roomInfoInitData?.live;
        const cid= livedata?.cid || livedata?.subcid;
        location.href = "https://cc.163.com/live/channel/?channelids=" + cid;
    }
},500);