Greasy Fork

Greasy Fork is available in English.

B站弹幕关闭

自动关闭哔哩哔哩 HTML5 播放器弹幕.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name:en-US          bilibili-Danmaku-Gate
// @name                B站弹幕关闭
// @description:en-US   Auto disable bilibili HTML5 player danmaku.
// @description         自动关闭哔哩哔哩 HTML5 播放器弹幕.
// @namespace           http://greasyfork.icu/users/135090
// @version             2022.02.16
// @author              Akatsuki Rui
// @license             MIT License
// @grant               GM_info
// @run-at              document-idle
// @description         fork from 374051,https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
// @match               *://www.bilibili.com/*video/*
// @match               *://www.bilibili.com/bangumi/play/*
// @match               *://www.bilibili.com/blackboard/*
// @match               *://www.bilibili.com/html/player.html*
// @match               *://player.bilibili.com/*
// ==/UserScript==
 
"use strict";
 
const SELECTOR_NATIVE = {
  on: "input:checked[class='bui-switch-input']",
  off: "input:not(:checked)[class='bui-switch-input']",
};
 
const SELECTOR_EMBED = {
  on: "div[class~='bilibili-player-video-btn-danmaku'][data-text='打开弹幕']",
  off: "div[class~='bilibili-player-video-btn-danmaku'][data-text='关闭弹幕']",
};
 
const IS_EMBED = document.location.hostname === "player.bilibili.com";
const SELECTOR = IS_EMBED ? SELECTOR_EMBED : SELECTOR_NATIVE;
 
// Skip Charge Support
function skipCharge() {
  const skip = () => {
    setTimeout(() => {
      document
        .getElementsByClassName("bilibili-player-electric-panel-jump")[0]
        .click();
    }, 10);
  };
 
  const videoElementA = document.querySelector("video");
  const videoElementB = document.querySelector("bwp-video");
 
  if (videoElementA) {
    videoElementA.onended = skip;
  } else if (videoElementB) {
    videoElementB.onended = skip;
  }
}
 
// Disable danmaku
function disableDanmaku() {
  const button = document.querySelector(SELECTOR.on);
 
  if (button) {
    button.click();
    skipCharge();
  }
 
  if (!document.querySelector(SELECTOR.off)) {
    setTimeout(disableDanmaku, 500);
  }
}
 
// Disable danmaku with PJAX detector
function disableDanmakuPJAX() {
  const obServer = new MutationObserver(disableDanmaku);
  const obTarget = document.getElementById("bilibili-player");
  const obOption = { childList: true };
 
  disableDanmaku();
  obServer.observe(obTarget, obOption);
}
 
// Redirect `bilibili.com/s/video/*` to `bilibili.com/video/*`
if (location.href.includes("/s/video/")) {
  location.replace(location.href.replace("/s/video/", "/video/"));
}
 
// Run disabler
IS_EMBED ? disableDanmaku() : disableDanmakuPJAX();