🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Greasy Fork is available in English.

B站快捷键增强:Enter全屏 + 倍速播放

在B站按Enter键全屏/退出全屏,按1/2/3键控制播放倍速

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name         B站快捷键增强:Enter全屏 + 倍速播放
// @namespace    https://dqtx.cc/
// @version      1.0
// @description  在B站按Enter键全屏/退出全屏,按1/2/3键控制播放倍速
// @author       Derek
// @match        *://www.bilibili.com/video/*
// @match        *://www.bilibili.com/bangumi/play/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    // 等待视频元素加载完成
    function waitForVideo() {
        const video = document.querySelector('video');
        if (video) {
            init(video);
        } else {
            setTimeout(waitForVideo, 500);
        }
    }

    function init(video) {
        console.log('[B站快捷键增强] 已启动');

        document.addEventListener('keydown', (e) => {
            // 忽略输入框(防止在评论区或搜索框触发)
            const tag = e.target.tagName.toLowerCase();
            if (tag === 'input' || tag === 'textarea' || e.target.isContentEditable) return;

            // 按 Enter 键切换全屏
            if (e.key === 'Enter') {
                e.preventDefault();
                if (!document.fullscreenElement) {
                    const player = document.querySelector('.bpx-player-video-wrap') || video;
                    if (player.requestFullscreen) player.requestFullscreen();
                } else {
                    document.exitFullscreen();
                }
            }

            // 按数字键控制播放速度
            if (['1', '2', '3'].includes(e.key)) {
                e.preventDefault();
                switch (e.key) {
                    case '1':
                        video.playbackRate = 1.0;
                        showToast('倍速:1.0x');
                        break;
                    case '2':
                        video.playbackRate = 2.0;
                        showToast('倍速:2.0x');
                        break;
                    case '3':
                        video.playbackRate = 3.0;
                        showToast('倍速:3.0x');
                        break;
                }
            }
        });

        // 简易提示气泡
        function showToast(text) {
            let toast = document.createElement('div');
            toast.innerText = text;
            Object.assign(toast.style, {
                position: 'fixed',
                bottom: '80px',
                left: '50%',
                transform: 'translateX(-50%)',
                background: 'rgba(0,0,0,0.7)',
                color: '#fff',
                padding: '8px 16px',
                borderRadius: '6px',
                fontSize: '14px',
                zIndex: 9999,
                transition: 'opacity 0.5s',
                opacity: 1
            });
            document.body.appendChild(toast);
            setTimeout(() => toast.style.opacity = 0, 1000);
            setTimeout(() => toast.remove(), 1500);
        }
    }

    waitForVideo();
})();