Greasy Fork

Greasy Fork is available in English.

BiliAuto

B站快捷键扩展,适合学习类视频.包括自动宽屏 低亮度模式 黑暗模式d 弹幕开关h 2倍速c 减速x 1倍速z

当前为 2021-08-06 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         BiliAuto
// @version      1.0.3
// @author       mishi321
// @description  B站快捷键扩展,适合学习类视频.包括自动宽屏 低亮度模式 黑暗模式d 弹幕开关h 2倍速c 减速x 1倍速z
// @match        https://www.bilibili.com/video/*
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_registerMenuCommand
// @grant        GM_unregisterMenuCommand
// @namespace    http://greasyfork.icu/users/789988
// ==/UserScript==

(function () {
    if (window.location.href.includes('note=open')) {
        window.location.href = window.location.href.replace('note=open', 'note=');
        return;
    }

    let speedIndex = 3;
    let lightOn = false, two2one = true;
    let filterOn = GM_getValue('filterOn'), widescreenOn = GM_getValue('widescreenOn');
    GM_registerMenuCommand("自动宽屏(刷新生效):" + widescreenOn, () => GM_setValue('widescreenOn', !widescreenOn));
    let id1 = GM_registerMenuCommand("低亮度模式:" + filterOn, filter);
    const video = document.getElementsByTagName('bwp-video')[0] || document.getElementsByTagName('video')[0];
    const observe = new MutationObserver(() => {
        if (filterOn === true && (two2one = !two2one)) {
            document.getElementsByClassName('bilibili-player-video')[0].style.cssText = "filter:brightness(0.6834);";
        }
    })

    filterOn && (document.getElementsByClassName('bilibili-player-video')[0].style.cssText = "filter:brightness(0.6834);") && observe.observe(video, { attributes: true });
    widescreenOn && video.addEventListener('play', () => document.getElementsByClassName('bilibili-player-video-btn-widescreen')[0]?.click(), { once: true });
    document.getElementsByClassName('list-box')[0] && video.addEventListener('ended', () => document.getElementsByClassName('bilibili-player-video-btn-next')[0].click());

    document.body.addEventListener('keypress', (e) => {
        if (e.target.nodeName !== 'BODY') {
            return;
        }
        switch (e.key) {
            case 'c':
                document.getElementsByClassName('bilibili-player-video-btn-speed-menu-list')[speedIndex = 0].click();
                break;
            case 'x':
                speedIndex < 5 && ++speedIndex;
                document.getElementsByClassName('bilibili-player-video-btn-speed-menu-list')[speedIndex].click();
                break;
            case 'z':
                document.getElementsByClassName('bilibili-player-video-btn-speed-menu-list')[speedIndex = 3].click();
                break;
            case 'd':
                if (lightOn = !lightOn) {
                    document.body.classList.add('player-mode-blackmask');
                    document.getElementById('heimu').style.display = 'block';
                    document.getElementById('bilibiliPlayer').classList.add('mode-light-off');
                }
                else {
                    document.body.classList.remove('player-mode-blackmask');
                    document.getElementById('heimu').style.display = 'none';
                    document.getElementById('bilibiliPlayer').classList.remove('mode-light-off');
                }
                break;
            case 'h':
                document.getElementsByClassName('bilibili-player-video-danmaku-switch')[0].children[0].click();
                break;
            default:
                break;
        }
    });

    function filter() {
        if (filterOn = !filterOn) {
            GM_setValue('filterOn', filterOn);
            document.getElementsByClassName('bilibili-player-video')[0].style.cssText = "filter:brightness(0.6834);";
            observe.observe(video, { attributes: true });
        } else {
            GM_setValue('filterOn', filterOn);
            document.getElementsByClassName('bilibili-player-video')[0].style.cssText = "";
        }
        GM_unregisterMenuCommand(id1);
        id1 = GM_registerMenuCommand("低亮度模式:" + filterOn, filter);
    }

})();