直播弹幕控制

自动关闭直播弹幕

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name                Live Danmaku Controller
// @name:en-US          Live Danmaku Controller
// @name:zh-CN          直播弹幕控制
// @description         Auto turn off live danmaku
// @description:en-US   Auto turn off live danmaku
// @description:zh-CN   自动关闭直播弹幕
// @namespace           live-danmaku-controller
// @version             2020.07.27.3
// @author              Akatsuki
// @license             MIT License
// @grant               GM_info
// @run-at              document-idle
// @match               *://live.bilibili.com/*
// @match               *://www.douyu.com/*
// @match               *://www.huya.com/*
// @match               *://www.yy.com/*
// ==/UserScript==

'use strict'

var selector = {
  'live.bilibili.com': {
    on: "i[class='live-icon-danmaku-on']",
    off: "i[class='live-icon-danmaku-off']",
  },
  'www.douyu.com': {
    on: "div[class^='showdanmu-']:not([class*='removed-'])",
    off: "div[class^='hidedanmu-']:not([class*='removed-'])",
  },
  'www.huya.com': {
    on: "div[class='danmu-show-btn'][title='关闭弹幕']",
    off: "div[class='danmu-show-btn danmu-hide-btn'][title='开启弹幕']",
  },
  'www.yy.com': {
    on: "div[class~='yc__bullet-comments-btn'][title='关闭弹幕']",
    off: "div[class~='yc__bullet-comments-btn'][title='打开弹幕']",
  },
}

var delay_site = ['www.yy.com']

var live_site = document.location.hostname

// Danmaku disabler
function disable_danmaku() {
  var button_on = document.querySelector(selector[live_site].on)
  if (button_on !== null) {
    button_on.click()
  }
  setTimeout(() => {
    if (document.querySelector(selector[live_site].off) === null) {
      disable_danmaku()
    }
  }, 500)
}

// Delay danmaku disabler for some sites (delay 10s)
// To fix the button showing as OFF, but danmaku still appear
if (delay_site.includes(live_site)) {
  setTimeout(disable_danmaku, 10000)
} else {
  disable_danmaku()
}