Pixiv 广告屏蔽

屏蔽 Pixiv 上的广告

目前为 2025-02-23 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Pixiv AdBlock
  3. // @name:en Pixiv AdBlock
  4. // @name:vi Pixiv Chặn Quảng Cáo
  5. // @name:zh-CN Pixiv 广告屏蔽
  6. // @name:zh-TW Pixiv 廣告封鎖
  7. // @name:ja Pixiv 広告ブロック
  8. // @namespace http://tampermonkey.net/
  9. // @version 0.5
  10. // @description Block ads on Pixiv
  11. // @description:en Block ads on Pixiv
  12. // @description:vi Chặn quảng cáo trên Pixiv
  13. // @description:zh-CN 屏蔽 Pixiv 上的广告
  14. // @description:zh-TW 封鎖 Pixiv 上的廣告
  15. // @description:ja Pixivの広告をブロックします
  16. // @match https://www.pixiv.net/*
  17. // @match https://touch.pixiv.net/*
  18. // @icon https://www.google.com/s2/favicons?sz=64&domain=pixiv.net
  19. // @license GPL-3.0-only
  20. // @author RenjiYuusei
  21. // @grant none
  22. // ==/UserScript==
  23.  
  24. (() => {
  25. // List of advertising selectors to be blocked
  26. const adSelectors = [
  27. ".ads", ".ad-container", ".billboard", ".ads-top-info",
  28. '[class*="ad-"]', '[class*="ads-"]', '[id*="ad-"]', '[id*="ads-"]',
  29. ".premium-lead-t", ".premium-lead-new-t", ".promotional-popup",
  30. ".ad-footer", ".ad-header", ".ad-sidebar", ".billboard-ad",
  31. ".js-premium-lead-header", ".js-premium-lead-footer", ".spotlight-ads",
  32. ".ad-interstitial", 'iframe[src*="ads"]', "div[data-ad-slot]",
  33. ".adsbygoogle", "#footer-ads", "#headerAd", ".ads-article-bottom",
  34. ".ads-article-top", ".ads-sidebar", ".advertisement", ".pixiv-ad",
  35. ".premium-promotion", "[data-gtm-recommend-ad]", '[data-gtm-value*="ad_"]',
  36. // Mobile specific selectors
  37. ".sp-ads", ".mobile-ad", ".mobile-advertisement",
  38. '[class*="sp-ad-"]', '[id*="sp-ad-"]',
  39. ".mobile-premium-lead", ".mobile-promotional",
  40. 'div[class*="mobile-ads"]', 'div[id*="mobile-ads"]',
  41. // Additional ad selectors
  42. ".sc-e9a5cd03-2", ".bGISCJ", "#adsdk--R1mhutb6",
  43. 'div[id^="adsdk--"]', 'iframe[data-uid^="R"]'
  44. ];
  45.  
  46. // Function to remove ads
  47. function removeAds() {
  48. // Remove elements matching the selectors
  49. adSelectors.forEach(selector => {
  50. document.querySelectorAll(selector).forEach(element => {
  51. element.remove();
  52. });
  53. });
  54.  
  55. // Remove ad close buttons and their containers
  56. document.querySelectorAll('img[src*="close_icon"][style*="position: absolute"], img[src*="close_button"]').forEach(img => {
  57. const container = img.closest('div');
  58. if (container) container.remove();
  59. });
  60. }
  61.  
  62. // Add CSS to hide ads
  63. function addBlockingStyles() {
  64. const style = document.createElement('style');
  65. style.textContent = `
  66. ${adSelectors.join(', ')},
  67. img[src*="close_icon"][style*="position: absolute"],
  68. img[src*="close_button"] {
  69. display: none !important;
  70. visibility: hidden !important;
  71. opacity: 0 !important;
  72. pointer-events: none !important;
  73. width: 0 !important;
  74. height: 0 !important;
  75. position: absolute !important;
  76. top: -9999px !important;
  77. left: -9999px !important;
  78. }
  79. /* Mobile specific styles */
  80. body.touch-device .ad-container,
  81. body.touch-device [class*="sp-ad"],
  82. body.touch-device .mobile-ad {
  83. display: none !important;
  84. }
  85. `;
  86. document.head.appendChild(style);
  87. }
  88.  
  89. // Observe DOM changes to remove dynamic ads
  90. function observeDOMChanges() {
  91. const observer = new MutationObserver((mutations) => {
  92. let hasNewNodes = mutations.some(mutation => mutation.addedNodes.length > 0);
  93. if (hasNewNodes) removeAds();
  94. });
  95.  
  96. observer.observe(document.body, {
  97. childList: true,
  98. subtree: true
  99. });
  100. }
  101.  
  102. // Initialize
  103. function init() {
  104. addBlockingStyles();
  105. removeAds();
  106. observeDOMChanges();
  107. // Process events to ensure ads are removed
  108. window.addEventListener('load', removeAds);
  109. document.addEventListener('DOMContentLoaded', removeAds);
  110. window.addEventListener('scroll', removeAds);
  111. // Handle touch events for mobile
  112. document.addEventListener('touchstart', removeAds, {passive: true});
  113. document.addEventListener('touchend', removeAds, {passive: true});
  114. setInterval(removeAds, 1000);
  115. }
  116.  
  117. // Run script
  118. init();
  119. })();

QingJ © 2025

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