直播弹幕控制

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

当前为 2019-08-27 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Live Danmaku Controller
  3. // @name:zh-CN 直播弹幕控制
  4. // @description Auto turn off danmaku, And press 'M' to control danmaku on/off.
  5. // @description:zh-CN 自动关闭弹幕, 按下 'M' 随时开关直播弹幕.
  6. // @namespace live-danmaku-controller
  7. // @version 2019.08.27
  8. // @author Akatsuki
  9. // @license MIT License
  10. // @inject-into content
  11. // @run-at document-idle
  12. // @require https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js
  13. // @require https://gf.qytechs.cn/scripts/48306-waitforkeyelements/code/waitForKeyElements.js?version=275769
  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. var 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. var delay_site = [
  42. 'www.yy.com'
  43. ]
  44.  
  45. var live_site = document.location.hostname
  46.  
  47. // Auto turn off danmaku
  48.  
  49. function disable_danmaku(button) {
  50. button[0].click()
  51. }
  52.  
  53. function disable_danmaku_delay() {
  54. var button = document.querySelector(selector[live_site].on)
  55. if (button !== null) {
  56. button.click()
  57. }
  58. }
  59.  
  60. if (delay_site.includes(live_site)) {
  61. setTimeout(disable_danmaku_delay, 10000)
  62. } else {
  63. waitForKeyElements(selector[live_site].on, disable_danmaku, false)
  64. }
  65.  
  66. // Detect 'm' and 'M' key and control danmaku on/off
  67.  
  68. function control_danmaku(button) {
  69. if (document.querySelector(button.on) !== null) {
  70. // on -> off
  71. document.querySelector(button.on).click()
  72. } else if (document.querySelector(button.off) !== null) {
  73. // off -> on
  74. document.querySelector(button.off).click()
  75. }
  76. }
  77.  
  78. $(document).keypress(function (key) {
  79. // detect 'm' or 'M' Key
  80. if (key.which === 77 || key.which === 109) {
  81. control_danmaku(selector[live_site])
  82. }
  83. })

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址