Greasy Fork is available in English.

BiliAuto

B站快捷键扩展,笔记功能全面增强,适合学习类视频.包括自动关闭笔记 自动关闭顶栏 自动宽屏 低亮度模式 黑暗模式h 2倍速c 减速x 1倍速z 打开笔记n 后退3秒(笔记)alt+j 暂停/播放(笔记)alt+k 前进3秒(笔记)alt+l 插入视频截图(笔记)alt+, 插入时间标记(笔记)alt+. 插入时间标记的确定按钮(笔记)alt+enter

// ==UserScript==
// @name         BiliAuto
// @version      1.2.13
// @author       mishi321
// @description  B站快捷键扩展,笔记功能全面增强,适合学习类视频.包括自动关闭笔记 自动关闭顶栏 自动宽屏 低亮度模式 黑暗模式h 2倍速c 减速x 1倍速z 打开笔记n 后退3秒(笔记)alt+j 暂停/播放(笔记)alt+k 前进3秒(笔记)alt+l 插入视频截图(笔记)alt+, 插入时间标记(笔记)alt+. 插入时间标记的确定按钮(笔记)alt+enter
// @match        https://www.bilibili.com/video/*
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_registerMenuCommand
// @grant        GM_unregisterMenuCommand
// @namespace    https://greasyfork.org/scripts/428878
// @license      MIT
// ==/UserScript==

(function () {

    let noteClose = GM_getValue('noteClose');
    if (noteClose == true && window.location.href.includes('note=open')) {
        window.location.href = window.location.href.replace('note=open', 'note=');
        return;
    }
    GM_registerMenuCommand("自动关闭笔记:" + noteClose, () => {
        GM_setValue('noteClose', !noteClose);
    });

    let headerClose = GM_getValue('headerClose');
    if (headerClose == true) {
        window.addEventListener('load', () => {
            document.getElementById('biliMainHeader').style.display = 'None';
        })
    }
    GM_registerMenuCommand("自动关闭顶栏:" + headerClose, () => {
        GM_setValue('headerClose', !headerClose);
    })

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

    document.body.addEventListener('keydown', (e) => {
        if (e.altKey) {
            switch (e.key) {
                case 'j':
                    video.currentTime -= 3;
                    break;
                case 'l':
                    video.currentTime += 3;
                    break;
                case 'k':
                    if (video.paused) {
                        video.play();
                    } else {
                        video.pause();
                    }
                    break;
                case ',':
                    document.getElementsByClassName('ql-capture-btn ql-bar')[0]?.click();
                    break;
                case '.':
                    document.getElementsByClassName('ql-tag-btn ql-bar-btn')[0]?.click();
                    break;
                case 'Enter':
                    document.getElementsByClassName('tag-dialog__btn--confirm')[0]?.click();
                    break;
                default:
                    break;
            }
        }
        if (e.target.nodeName !== 'BODY') return;
        if (e.ctrlKey === false) {
            switch (e.key) {
                case 'c':
                    document.getElementsByClassName('bpx-player-ctrl-playbackrate-menu-item')[speedIndex = 0].click();
                    break;
                case 'x':
                    speedIndex < 5 && ++speedIndex;
                    document.getElementsByClassName('bpx-player-ctrl-playbackrate-menu-item')[speedIndex].click();
                    break;
                case 'z':
                    document.getElementsByClassName('bpx-player-ctrl-playbackrate-menu-item')[speedIndex = 3].click();
                    break;
                case 'h':
                    if (lightOn = !lightOn) {
                        document.getElementsByClassName("bpx-docker")[0].classList.add("bpx-state-light-off");
                    } else {
                        document.getElementsByClassName("bpx-docker")[0].classList.remove("bpx-state-light-off");
                    }
                    break;
                case 'n':
                    document.getElementsByClassName('note-btn')[0]?.click();
                    document.getElementsByClassName('note-list-btn')[0]?.click();
                    break;
                default:
                    break;
            }
        }
    });

    let video = document.getElementsByTagName('video')[0] || document.getElementsByTagName('bwp-video')[0];
    filterOn && (document.getElementsByClassName('bpx-player-video-wrap')[0].style.cssText = "filter:brightness(0.6834);") && filterOB.observe(video, { attributes: true });
    document.getElementsByClassName('list-box')[0] && video.addEventListener('ended', () => document.getElementsByClassName('bpx-player-ctrl-btn-icon')[2].click());

    widescreenOn && video.addEventListener("playing", () => {
        setTimeout(() => document.getElementsByClassName("bpx-player-ctrl-wide")[0].click(), 500);
    }, { once: true });

    function filter() {
        if (filterOn = !filterOn) {
            GM_setValue('filterOn', filterOn);
            document.getElementsByClassName('bilibili-player-video')[0].style.cssText = "filter:brightness(0.6834);";
            filterOB.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);
    }

})();