去你妈的批站诈骗广告( bilibili,B站去广告 )

bilibili,B站,去广告,屏蔽小火箭推广视频,屏蔽首页左侧大图滑动推荐栏,屏蔽直播主页顶部自动播放的直播

  1. // ==UserScript==
  2. // @name 去你妈的批站诈骗广告( bilibili,B站去广告 )
  3. // @version 1.10
  4. // @description bilibili,B站,去广告,屏蔽小火箭推广视频,屏蔽首页左侧大图滑动推荐栏,屏蔽直播主页顶部自动播放的直播
  5. // @author 爆菊大师
  6. // @match *://*.bilibili.com/*
  7. // @icon https://www.bilibili.com/favicon.ico
  8. // @grant none
  9. // @license MIT
  10. // @namespace http://tampermonkey.net/
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15. const currentHost = window.location.hostname;
  16. const currentPath = window.location.pathname;
  17. const injectStyle = (css) => {
  18. const style = document.createElement('style');
  19. style.textContent = css;
  20. document.head.appendChild(style);
  21. };
  22. if (currentHost === 'live.bilibili.com' && (currentPath === '/' || currentPath === '')) {
  23. injectStyle(`
  24. .player-area-ctnr.border-box.p-relative.t-center { display: none !important; }
  25. `);
  26. const originalPlay = HTMLMediaElement.prototype.play;
  27. HTMLMediaElement.prototype.play = function() {
  28. const stack = new Error().stack || '';
  29. if (stack.includes('home-player.prod.min.js')) {
  30. this.pause();
  31. this.currentTime = 0;
  32. this.removeAttribute('autoplay');
  33. return Promise.reject(new DOMException('play() failed'));
  34. }
  35. return originalPlay.apply(this, arguments);
  36. };
  37. }
  38. if (currentHost === 'www.bilibili.com' && (currentPath === '/' || currentPath === '')) {
  39. injectStyle(`
  40. .bili-video-card__skeleton.loading_animation,
  41. .recommended-swipe.grid-anchor,
  42. .bili-live-card.is-rcmd.enable-no-interest,
  43. .ad-report.ad-floor-exp.left-banner,
  44. .floor-single-card,
  45. .fixed-card { display: none !important; }
  46. .feed-card { margin-top: 0 !important; }
  47. `);
  48. const selectors = {
  49. pseudo: '.bili-video-card.is-rcmd',
  50. icons: '.vui_icon.bili-video-card__stats--icon',
  51. adFeed: '.bili-video-card__mask .bili-video-card__stats--text'
  52. };
  53. const isBlocked = (element) => {
  54. if (element.dataset.checked) return element.dataset.blocked === 'true';
  55. const content = getComputedStyle(element, '::before').content;
  56. const blocked = content.includes('AdGuard') || content.includes('AdBlock');
  57. element.dataset.checked = 'true';
  58. element.dataset.blocked = blocked;
  59. return blocked;
  60. };
  61. const checkElements = (selector, condition, parentSelector) => {
  62. document.querySelectorAll(selector).forEach(el => {
  63. const target = parentSelector ? el.closest(parentSelector) : el;
  64. if (target && (!condition || condition(el))) {
  65. target.style.display = 'none';
  66. target.dataset.processed = 'true';
  67. }
  68. });
  69. };
  70. const debounce = (fn, delay = 100) => {
  71. let timeout;
  72. return (...args) => {
  73. clearTimeout(timeout);
  74. timeout = setTimeout(() => fn(...args), delay);
  75. };
  76. };
  77. const observer = new MutationObserver(debounce(() => {
  78. checkElements(selectors.pseudo, el =>
  79. isBlocked(el) || [...el.children].some(isBlocked)
  80. );
  81. checkElements(selectors.icons, null, '.bili-video-card');
  82. checkElements(selectors.adFeed, el =>
  83. el.textContent.includes('广告'), '.bili-video-card__wrap'
  84. );
  85. }));
  86.  
  87. observer.observe(document.body, { subtree: true, childList: true });
  88. }
  89. if (currentHost === 'www.bilibili.com' && currentPath.startsWith('/video/')) {
  90. injectStyle(`
  91. .ad-report.ad-floor-exp.left-banner,
  92. .ad-report.ad-floor-exp.right-bottom-banner,
  93. .activity-m-v1.act-end,
  94. .activity-m-v1.act-now,
  95. .video-card-ad-small,
  96. .video-page-game-card-small,
  97. .slide-ad-exp { display: none !important; }
  98. `);
  99. }
  100. })();