Bilibili Live Enhancer

Stream filtering + Gift bar removal + Live counter for Bilibili

目前为 2025-03-25 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Bilibili Live Enhancer
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2
  5. // @description Stream filtering + Gift bar removal + Live counter for Bilibili
  6. // @author Gavin Hon
  7. // @match https://live.bilibili.com/*
  8. // @grant none
  9. // @run-at document-idle
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Configuration - Stream Filtering
  17. const LIVE_FILTER_SELECTOR = '.face.living';
  18. const TARGET_CONTAINER_SELECTOR = '.single';
  19. const NAME_SELECTOR = '.name';
  20. const BLOCKED_NAME = '花芽荔枝';
  21. const COUNTER_SELECTOR = '.mount';
  22. const COUNTER_PREFIX = ' (Streaming: ';
  23.  
  24. // Configuration - Gift Bar Removal
  25. const GIFT_BAR_ID = 'gift-control-vm';
  26.  
  27. let liveCount = 0;
  28. let counterElement = null;
  29.  
  30. // Core Functions
  31. function updateCounter() {
  32. if (!counterElement) {
  33. counterElement = document.querySelector(COUNTER_SELECTOR);
  34. if (!counterElement) return;
  35. }
  36. counterElement.textContent = `${COUNTER_PREFIX}${liveCount})`;
  37. }
  38.  
  39. function filterStreamers() {
  40. liveCount = 0;
  41. document.querySelectorAll(TARGET_CONTAINER_SELECTOR).forEach(container => {
  42. // Name filter
  43. const nameElem = container.querySelector(NAME_SELECTOR);
  44. if (nameElem?.textContent.includes(BLOCKED_NAME)) {
  45. container.remove();
  46. return;
  47. }
  48.  
  49. // Live status check
  50. const isLive = container.querySelector(LIVE_FILTER_SELECTOR);
  51. isLive ? liveCount++ : container.remove();
  52. });
  53.  
  54. updateCounter();
  55. }
  56.  
  57. function removeGiftBar() {
  58. const giftBar = document.getElementById(GIFT_BAR_ID);
  59. if (giftBar) giftBar.remove();
  60. }
  61.  
  62. // Unified observer for all DOM changes
  63. const mainObserver = new MutationObserver((mutations) => {
  64. filterStreamers();
  65. removeGiftBar();
  66. });
  67.  
  68. // Initial setup
  69. function initialize() {
  70. // Run features immediately
  71. removeGiftBar();
  72. filterStreamers();
  73.  
  74. // Start observing
  75. mainObserver.observe(document.body, {
  76. subtree: true,
  77. childList: true,
  78. attributes: false,
  79. characterData: false
  80. });
  81.  
  82. // Handle SPA navigation
  83. window.addEventListener('popstate', initialize);
  84. window.addEventListener('pushstate', initialize);
  85. }
  86.  
  87. // Start the script
  88. initialize();
  89. })();

QingJ © 2025

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