turn off bilibili danmaku

默认关闭弹幕功能

  1. // ==UserScript==
  2. // @name turn off bilibili danmaku
  3. // @description 默认关闭弹幕功能
  4. // @namespace wulawulawula
  5. // @author 愛梨
  6. // @license GNU GPLv3
  7. // @version 20180330
  8. // @encoding utf-8
  9. // @grant none
  10. // @include https://www.bilibili.com/video/av*
  11. // @include http://www.bilibili.com/video/av*
  12. // @include https://bangumi.bilibili.com/anime/*/play*
  13. // @include http://bangumi.bilibili.com/anime/*/play*
  14. // @include https://live.bilibili.com*
  15. // @include http://live.bilibili.com*
  16. // @include *://www.bilibili.com/bangumi/play/ep*
  17. // @include *://www.bilibili.com/bangumi/play/ss*
  18. // @include *://www.bilibili.com/watchlater/#/av*
  19. // @run-at document-end
  20. // ==/UserScript==
  21.  
  22.  
  23. var check;
  24.  
  25. function checkPlayerLoaded() {
  26. console.log('[SCRIPT-TurnOffDanmaku] check')
  27.  
  28. let iframe, animeP, videoP, player
  29.  
  30. iframe = document.querySelector('iframe')
  31. if (iframe) {
  32. animeP = iframe.contentWindow.document.body.querySelector(
  33. `#bilibiliPlayer`)
  34. }
  35.  
  36. videoP = document.body.querySelector('#bilibiliPlayer')
  37.  
  38. player = animeP || videoP
  39.  
  40. let video = player.querySelector('video')
  41. if (video) {
  42. clearInterval(check)
  43. console.log('[SCRIPT-TurnOffDanmaku] bilibili player loaded')
  44. trigger()
  45. }
  46. }
  47.  
  48.  
  49.  
  50.  
  51. function trigger() {
  52. let iframe, animeP, videoP, player
  53.  
  54. iframe = document.querySelector('iframe')
  55. if (iframe) {
  56. animeP = iframe.contentWindow.document.body.querySelector(
  57. `#bilibiliPlayer`)
  58. }
  59.  
  60. videoP = document.body.querySelector('#bilibiliPlayer')
  61.  
  62. player = animeP || videoP
  63.  
  64. let btn = player.querySelector(`
  65. .bilibili-player-video-btn.bilibili-player-video-btn-danmaku`)
  66. let panel = player.querySelector(`
  67. .bilibili-player-danmaku-setting-lite-panel`)
  68. console.log('[SCRIPT-TurnOffDanmaku] Btn: \n', btn)
  69. btn.click();
  70. if (btn.getAttribute('name') === 'ctlbar_danmuku_on') {
  71. panel.style.display = 'none';
  72. }
  73. }
  74.  
  75.  
  76. function execOnVideosPage() {
  77.  
  78. check = setInterval(checkPlayerLoaded, 1000)
  79.  
  80. window.onhashchange = () => {
  81. console.log('hash changed')
  82. clearInterval(check)
  83. check = setInterval(checkPlayerLoaded, 1000)
  84. }
  85.  
  86. document.addEventListener('keypress', (evt) => {
  87. if (evt.key === 'm' && evt.altKey) {
  88. console.log('[SCRIPT-TurnOffDanmaku] alt + m')
  89. trigger()
  90. }
  91. })
  92.  
  93. // https://stackoverflow.com/questions/5129386
  94. window.addEventListener('pushState', function(e) {
  95. console.log('history pushState');
  96. clearInterval(check)
  97. console.log('check canceled');
  98. check = setInterval(checkPlayerLoaded, 1000)
  99. })
  100.  
  101.  
  102. }
  103.  
  104.  
  105. function checkLivePlayerLoaded() {
  106. // console.log('[SCRIPT-TurnOffDanmaku] check')
  107. try {
  108. let liveplayer = document.body.querySelector('#live-player')
  109. let livevideo = document.body.querySelector('#live-video')
  110. let player = liveplayer || livevideo
  111. let video = player.querySelector('video')
  112. if (video) {
  113. clearInterval(check)
  114. console.log('[SCRIPT-TurnOffDanmaku] bilibili live player loaded')
  115. livetrigger()
  116. }
  117. }
  118. catch(err){}
  119. }
  120.  
  121.  
  122. function livetrigger() {
  123. let btn = document.querySelector(`
  124. .bilibili-live-player-video-controller-hide-danmaku-btn`)
  125. btn = btn.querySelector('button')
  126. btn.click()
  127. }
  128.  
  129.  
  130. function execOnLivePage() {
  131.  
  132. check = setInterval(checkLivePlayerLoaded, 1000)
  133.  
  134. let aitem = document.querySelectorAll('.player-aside div.aside-item')
  135.  
  136. Array.from(aitem).forEach(item => {
  137. item.addEventListener('click', function(evt) {
  138. clearInterval(check)
  139. check = setInterval(checkLivePlayerLoaded, 1000)
  140. })
  141. })
  142.  
  143. document.addEventListener('keypress', (evt) => {
  144. if (evt.key === 'm' && evt.altKey) {
  145. console.log('[SCRIPT-TurnOffDanmaku] alt + m')
  146. livetrigger()
  147. }
  148. })
  149. }
  150.  
  151.  
  152. function historyPushState(evt) {
  153. let oevt = history[evt]
  154. return function() {
  155. let nevt = oevt.apply(this, arguments)
  156. let pushstate = new Event(evt)
  157. pushstate.arguments = arguments
  158. window.dispatchEvent(pushstate)
  159. return nevt
  160. }
  161. }
  162.  
  163.  
  164. history.pushState = historyPushState('pushState')
  165.  
  166.  
  167. function main() {
  168.  
  169. if (location.hostname === 'live.bilibili.com') {
  170. execOnLivePage()
  171. }
  172. else {
  173. execOnVideosPage()
  174. }
  175.  
  176. }
  177.  
  178. main()

QingJ © 2025

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