Greasy Fork

Greasy Fork is available in English.

纯净版斗鱼(douyu)

斗鱼纯净版(douyu.com),斗鱼极简版,只保留直播和弹幕

当前为 2025-05-30 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         纯净版斗鱼(douyu)
// @namespace    https://github.com/ljezio
// @version      2.1.1
// @description  斗鱼纯净版(douyu.com),斗鱼极简版,只保留直播和弹幕
// @homepage     https://github.com/ljezio/pure-douyu
// @author       ljezio
// @license      MIT
// @match        https://www.douyu.com/*
// @icon         https://www.douyu.com/favicon.ico
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    const player = document.querySelector('.layout-Player');
    const root = document.querySelector('#root') ||
        document.querySelector('section[class="layout-Container"]');
    if (!root || !player) return;
    dbClick(player);
    removeNude(root, player);
    clearPayer(player);
})();

/**
 * 双击全屏
 */
function dbClick(player) {
    player.ondblclick = event => {
        event.stopPropagation();
        if (!document.fullscreenElement) {
            const element = document.querySelector('div[title="全屏"]');
            if (element) {
                element.click();
            } else {
                toast.show("等待加载完成...");
            }
        } else {
            document.exitFullscreen().then();
        }
    };
}

/**
 * 隐藏无用元素
 */
function removeNude(root, player) {
    root.style.padding = '0';
    root.appendChild(player);
    for (let node of root.children) {
        if (!node.isSameNode(player)) {
            setDisplayNone(node);
        }
    }
    new MutationObserver(mutations => {
        for (let mutation of mutations) {
            if (mutation.type !== 'childList') {
                continue;
            }
            for (let node of mutation.addedNodes) {
                // 移除客服按钮
                if (node.className === 'bacpCommonKeFu  ' || node.id === 'webmActKefuWeidget') {
                    setDisplayNone(node);
                }
            }
        }
    }).observe(document.querySelector('body'), {childList: true})
}

/**
 * 播放器隐藏无用元素
 */
function clearPayer(player) {
    setDisplayNone(document.querySelector('#js-player-title'));
    setDisplayNone(document.querySelector('.layout-Player .layout-Player-aside'));
    document.querySelector('#js-player-toolbar')?.remove();
    // 播放器自适应宽高
    const windowHeight = innerHeight - 10;
    const height = player.offsetHeight;
    if (height > windowHeight) {
        player.style.width = innerWidth * (windowHeight / height) + 'px'
    }
    player.style.margin = '0 auto';
    // 移除播放器控制栏多余按钮
    const interval = setInterval(() => {
        const element = document.querySelector('div[class^="controlbar-"]');
        if (!element) return;
        element.style.width = '100%';
        setDisplayNone(document.querySelector('div[title="主播精彩时刻"]'));
        setDisplayNone(document.querySelector('div[title="问题反馈"]'));
        setDisplayNone(document.querySelector('div[title="多路观看"]'));
        setDisplayNone(document.querySelector('div[title="网页全屏"]'));
        setDisplayNone(document.querySelector('div[title="退出网页全屏"]'));
        clearInterval(interval)
    }, 1000);
}

/**
 * 隐藏元素
 */
function setDisplayNone(node) {
    if (!node) return;
    node.style.display = "none";
}

/**
 * toast
 */
const toast = {
    _toast: null,
    show(msg) {
        if (this._toast) return;
        this._toast = document.createElement('div');
        this._toast.innerHTML = msg;
        this._toast.style.cssText = `font-size: 20px;
                                   color: rgb(255, 255, 255);
                                   background-color: rgba(0, 0, 0, 0.6);
                                   padding: 10px 15px;
                                   margin: 0 0 0 -60px;
                                   border-radius: 4px;
                                   position: fixed;
                                   top: 20%;
                                   left: 50%;
                                   text-align: center;`;
        document.body.appendChild(this._toast);
        setTimeout(() => {
            document.body.removeChild(this._toast)
            this._toast = null
        }, 1500);
    }
}