Greasy Fork

Greasy Fork is available in English.

bilibili 弹幕关闭

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

当前为 2020-07-30 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name                bilibili Danmaku Disabler
// @name:en-US          bilibili Danmaku Disabler
// @name:zh-CN          bilibili 弹幕关闭
// @description         Auto disable bilibili HTML5 player danmaku
// @description:en-US   Auto disable bilibili HTML5 player danmaku
// @description:zh-CN   自动关闭哔哩哔哩 HTML5 播放器弹幕
// @namespace           bilibili-danmaku-disabler
// @version             2020.07.30.1
// @author              Akatsuki
// @license             MIT License
// @grant               GM_info
// @run-at              document-idle
// @match               *://www.bilibili.com/*video/*
// @match               *://www.bilibili.com/bangumi/play/*
// @match               *://www.bilibili.com/blackboard/*
// @match               *://player.bilibili.com/*
// ==/UserScript==

"use strict";

const selectorNative = {
  on: "input[class='bui-switch-input']:checked",
  off: "input[class='bui-switch-input']:not(:checked)",
};

const selectorEmbed = {
  on: "div[class~='bilibili-player-video-btn-danmaku'][data-text='打开弹幕']",
  off: "div[class~='bilibili-player-video-btn-danmaku'][data-text='关闭弹幕']",
};

let selector = selectorNative;
if (document.location.hostname === "player.bilibili.com") {
  selector = selectorEmbed;
}

// Danmaku disabler
function disableDanmaku() {
  let isDisabled = false;
  let previousHref = document.location.href;

  setInterval(() => {
    // PJAX / History.pushState detect
    if (previousHref !== document.location.href) {
      previousHref = document.location.href;
      isDisabled = false;
    }
    // Main Disabler
    if (isDisabled === false) {
      let buttonOn = document.querySelector(selector.on);
      if (buttonOn !== null) {
        buttonOn.click();
        isDisabled = true;
      }
    }
  }, 500);
}

disableDanmaku();