Bilibili 默认开启弹幕(自用)

在Bilibili视频播放页强制默认开启弹幕

  1. // ==UserScript==
  2. // @name Bilibili 默认开启弹幕(自用)
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description 在Bilibili视频播放页强制默认开启弹幕
  6. // @author Jinyou
  7. // @license MIT
  8. // @match *://www.bilibili.com/video/*
  9. // @icon https://www.bilibili.com/favicon.ico
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. function enableDanmu() {
  17. const danmuButton = document.querySelector('#bilibili-player > div.bpx-docker.bpx-docker-major > div.bpx-player-container.bpx-state-paused > div.bpx-player-primary-area:first-child > div.bpx-player-sending-area:last-child > div.bpx-player-sending-bar > div.bpx-player-dm-root:last-child > div.bpx-player-dm-switch.bui.bui-danmaku-switch:first-child > div.bui-area > input.bui-danmaku-switch-input:first-child');
  18. if (danmuButton && !danmuButton.checked) {
  19. danmuButton.click();
  20. }
  21. }
  22.  
  23. function checkDanmu() {
  24. // 确保视频播放器已经加载
  25. const videoPlayer = document.querySelector('.bpx-player-container');
  26. if (videoPlayer) {
  27. enableDanmu();
  28. } else {
  29. // 如果播放器未加载,则稍后再试
  30. setTimeout(checkDanmu, 1000);
  31. }
  32. }
  33.  
  34. // 页面加载完成后执行
  35. window.addEventListener('load', checkDanmu);
  36.  
  37. // 处理页面动态加载
  38. const observer = new MutationObserver(function() {
  39. checkDanmu();
  40. });
  41.  
  42. observer.observe(document.body, { childList: true, subtree: true });
  43.  
  44. })();

QingJ © 2025

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