Greasy Fork

Greasy Fork is available in English.

直播弹幕控制

自动关闭弹幕, 按下 'M' 随时开关直播弹幕.

当前为 2019-06-25 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name                Live Danmaku Controller
// @name:zh-CN          直播弹幕控制
// @description         Auto turn off danmaku, And press 'M' to control danmaku on/off.
// @description:zh-CN   自动关闭弹幕, 按下 'M' 随时开关直播弹幕.
// @namespace           live-danmaku-controller
// @version             2019.06.25
// @author              kazetoyuki
// @license             MIT License
// @run-at              document-idle
// @require             https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
// @require             http://greasyfork.icu/scripts/48306-waitforkeyelements/code/waitForKeyElements.js?version=275769
// @include             *://live.bilibili.com/*
// @include             *://www.douyu.com/*
// @include             *://www.huya.com/*
// @include             *://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 delaySite = [
  'www.yy.com'
]

var liveSite = document.location.hostname

// Auto turn off danmaku

function disableDanmaku (button) {
  button[0].click()
}

function disableDanmakuDelay () {
  var button = document.querySelector(selector[liveSite].on)
  if (button !== null) {
    button.click()
  }
}

if (delaySite.includes(liveSite)) {
  setTimeout(disableDanmakuDelay, 5000)
} else {
  waitForKeyElements(selector[liveSite].on, disableDanmaku, false)
}

// Detect 'm' and 'M' key and control danmaku on/off

function controlDanmaku (button) {
  if (document.querySelector(button.on) !== null) {
    // on -> off
    document.querySelector(button.on).click()
  } else if (document.querySelector(button.off) !== null) {
    // off -> on
    document.querySelector(button.off).click()
  }
}

$(document).keypress(function (key) {
  // detect 'm' or 'M' Key
  if (key.which === 77 || key.which === 109) {
    controlDanmaku(selector[liveSite])
  }
})