直播弹幕控制

自动关闭直播弹幕

目前为 2020-07-28 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Live Danmaku Controller
  3. // @name:en-US Live Danmaku Controller
  4. // @name:zh-CN 直播弹幕控制
  5. // @description Auto turn off live danmaku
  6. // @description:en-US Auto turn off live danmaku
  7. // @description:zh-CN 自动关闭直播弹幕
  8. // @namespace live-danmaku-controller
  9. // @version 2020.07.28
  10. // @author Akatsuki
  11. // @license MIT License
  12. // @grant GM_info
  13. // @run-at document-idle
  14. // @match *://live.bilibili.com/*
  15. // @match *://www.douyu.com/*
  16. // @match *://www.huya.com/*
  17. // @match *://www.yy.com/*
  18. // ==/UserScript==
  19.  
  20. 'use strict'
  21.  
  22. const selector = {
  23. 'live.bilibili.com': {
  24. on: "i[class='live-icon-danmaku-on']",
  25. off: "i[class='live-icon-danmaku-off']"
  26. },
  27. 'www.douyu.com': {
  28. on: "div[class^='showdanmu-']:not([class*='removed-'])",
  29. off: "div[class^='hidedanmu-']:not([class*='removed-'])"
  30. },
  31. 'www.huya.com': {
  32. on: "div[class='danmu-show-btn'][title='关闭弹幕']",
  33. off: "div[class='danmu-show-btn danmu-hide-btn'][title='开启弹幕']"
  34. },
  35. 'www.yy.com': {
  36. on: "div[class~='yc__bullet-comments-btn'][title='关闭弹幕']",
  37. off: "div[class~='yc__bullet-comments-btn'][title='打开弹幕']"
  38. }
  39. }
  40.  
  41. const delaySite = ['www.yy.com']
  42.  
  43. var liveSite = document.location.hostname
  44.  
  45. // Danmaku disabler
  46. function disableDanmaku () {
  47. var buttonOn = document.querySelector(selector[liveSite].on)
  48. if (buttonOn !== null) {
  49. buttonOn.click()
  50. }
  51. setTimeout(() => {
  52. if (document.querySelector(selector[liveSite].off) === null) {
  53. disableDanmaku()
  54. }
  55. }, 500)
  56. }
  57.  
  58. // Delay danmaku disabler for some sites (Delay 10s)
  59. // Fix the button is showing as OFF, but danmaku still appear
  60. if (delaySite.includes(liveSite)) {
  61. setTimeout(disableDanmaku, 10000)
  62. } else {
  63. disableDanmaku()
  64. }