BiliBili 一键开关 弹幕 danmu

通过 “/” 键控制弹幕开关,也可通过更改 ”danmu“ 变量 来修改热键. <br> 默认初始关闭弹幕,可通过更改”defaultClosing“变量为0,以便开启弹幕.

目前為 2022-03-16 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         BiliBili 一键开关 弹幕 danmu
// @namespace    http://tampermonkey.net/
// @version      v1.0
// @description  通过 “/” 键控制弹幕开关,也可通过更改 ”danmu“ 变量 来修改热键. <br> 默认初始关闭弹幕,可通过更改”defaultClosing“变量为0,以便开启弹幕.
// @author       Ben
// @match        *://*.bilibili.com/*
// @grant        none
// @require https://cdn.staticfile.org/jquery/2.1.4/jquery.min.js
// @license MIT
// ==/UserScript==

// code reference : https://github.com/akiirui/userscript/blob/bilibili-danmaku-disabler/userscript.js

var danMu = 191; //"/",可以自己更改
var defaultClosing = 1;// 是否默认开启弹幕. 1:默认关闭,0:默认开启

const button = ".bui-switch-input";
const danmuLabel = ".choose_danmaku";
const danmuHover = ".bilibili-player-video-danmaku-switch.bui.bui-switch"

$(document).ready(function() {
        //Close the danmu by default?
        function defaultClosing(){
            if($(danmuHover).length>0 && $(button).length>0 ){
                              clearInterval(id);
                              //$(danmuHover).dispatchEvent( new MouseEvent('mouseover', {'view': window, 'bubbles': true, 'cancelable': true }) );
                              $(danmuHover).mouseover(); // danmuLabel-class only appear after this excution.
                              //console.log('aa');
                              console.log($(danmuHover).attr("aria-label") + " ben");
                              console.log($(danmuLabel).text() + " ben");
                              if( $(danmuLabel).text() == "关闭弹幕" && defaultClosing){
                                // Run disabler
                                $(button).click();
                              }
            }
        }
        var id = setInterval(defaultClosing, 500);

        //在页面内跳转到其它视频
        $(document).on('click','.video-page-card',function(){
            id = setInterval(defaultClosing, 500);
		});

		$(document).keydown(function(event){//listener,调用键盘编码,按了键盘回调keydown里的function(event)函数,event就是你按的那个按键的code码
            switch(event.keyCode){
                case danMu:
                    $(button).click();
                break;
            }
		});
});