🏠 Home 

Pixiv AdBlock

Block ads on Pixiv


Install this script?
  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. // List of advertising selectors to be blocked
  25. const adSelectors = [
  26. ".ads", ".ad-container", ".billboard", ".ads-top-info",
  27. '[class*="ad-"]', '[class*="ads-"]', '[id*="ad-"]', '[id*="ads-"]',
  28. ".premium-lead-t", ".premium-lead-new-t", ".promotional-popup",
  29. ".ad-footer", ".ad-header", ".ad-sidebar", ".billboard-ad",
  30. ".js-premium-lead-header", ".js-premium-lead-footer", ".spotlight-ads",
  31. ".ad-interstitial", 'iframe[src*="ads"]', "div[data-ad-slot]",
  32. ".adsbygoogle", "#footer-ads", "#headerAd", ".ads-article-bottom",
  33. ".ads-article-top", ".ads-sidebar", ".advertisement", ".pixiv-ad",
  34. ".premium-promotion", "[data-gtm-recommend-ad]", '[data-gtm-value*="ad_"]',
  35. // Mobile specific selectors
  36. ".sp-ads", ".mobile-ad", ".mobile-advertisement",
  37. '[class*="sp-ad-"]', '[id*="sp-ad-"]',
  38. ".mobile-premium-lead", ".mobile-promotional",
  39. 'div[class*="mobile-ads"]', 'div[id*="mobile-ads"]',
  40. // Additional ad selectors
  41. ".sc-e9a5cd03-2", ".bGISCJ", "#adsdk--R1mhutb6",
  42. 'div[id^="adsdk--"]', 'iframe[data-uid^="R"]'
  43. ];
  44. // Function to remove ads
  45. function removeAds() {
  46. // Remove elements matching the selectors
  47. adSelectors.forEach(selector => {
  48. document.querySelectorAll(selector).forEach(element => {
  49. element.remove();
  50. });
  51. });
  52. // Remove ad close buttons and their containers
  53. document.querySelectorAll('img[src*="close_icon"][style*="position: absolute"], img[src*="close_button"]').forEach(img => {
  54. const container = img.closest('div');
  55. if (container) container.remove();
  56. });
  57. }
  58. // Add CSS to hide ads
  59. function addBlockingStyles() {
  60. const style = document.createElement('style');
  61. style.textContent = `
  62. ${adSelectors.join(', ')},
  63. img[src*="close_icon"][style*="position: absolute"],
  64. img[src*="close_button"] {
  65. display: none !important;
  66. visibility: hidden !important;
  67. opacity: 0 !important;
  68. pointer-events: none !important;
  69. width: 0 !important;
  70. height: 0 !important;
  71. position: absolute !important;
  72. top: -9999px !important;
  73. left: -9999px !important;
  74. }
  75. /* Mobile specific styles */
  76. body.touch-device .ad-container,
  77. body.touch-device [class*="sp-ad"],
  78. body.touch-device .mobile-ad {
  79. display: none !important;
  80. }
  81. `;
  82. document.head.appendChild(style);
  83. }
  84. // Observe DOM changes to remove dynamic ads
  85. function observeDOMChanges() {
  86. const observer = new MutationObserver((mutations) => {
  87. let hasNewNodes = mutations.some(mutation => mutation.addedNodes.length > 0);
  88. if (hasNewNodes) removeAds();
  89. });
  90. observer.observe(document.body, {
  91. childList: true,
  92. subtree: true
  93. });
  94. }
  95. // Initialize
  96. function init() {
  97. addBlockingStyles();
  98. removeAds();
  99. observeDOMChanges();
  100. // Process events to ensure ads are removed
  101. window.addEventListener('load', removeAds);
  102. document.addEventListener('DOMContentLoaded', removeAds);
  103. window.addEventListener('scroll', removeAds);
  104. // Handle touch events for mobile
  105. document.addEventListener('touchstart', removeAds, {passive: true});
  106. document.addEventListener('touchend', removeAds, {passive: true});
  107. setInterval(removeAds, 1000);
  108. }
  109. // Run script
  110. init();
  111. })();