// ==UserScript== // @name Hide Promotion Advertisement at Zhihu Site // @namespace http://tampermonkey.net/ // @version 0.1 // @description Hide specific advertisement elements on Zhihu // @author aspen138 // @match *://*.zhihu.com/* // @grant none // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; // Function to hide the advertisement elements function hideAds() { // Hide elements with class name 'Pc-word-card' var adElements1 = document.querySelectorAll('.Pc-word-card'); adElements1.forEach(function(element) { element.style.display = 'none'; }); // Hide elements with class name 'Banner-link' (common in ads) var adElements2 = document.querySelectorAll('.Banner-link'); adElements2.forEach(function(element) { element.style.display = 'none'; }); // Hide elements with class name 'Banner-adTag' (label for ads) var adElements3 = document.querySelectorAll('.Banner-adTag'); adElements3.forEach(function(element) { element.style.display = 'none'; }); // Hide elements with class containing 'AdvertImg' (common in ads) var adElements4 = document.querySelectorAll('.AdvertImg'); adElements4.forEach(function(element) { element.style.display = 'none'; }); // Hide iframe advertisements var adIframes = document.querySelectorAll('iframe[src*="baidu.com"]'); adIframes.forEach(function(iframe) { iframe.style.display = 'none'; }); // Hide close button on ads (optional) var closeButtons = document.querySelectorAll('.Pc-card-button-close'); closeButtons.forEach(function(button) { button.style.display = 'none'; }); } // Run the function to hide the elements when the page loads window.addEventListener('load', hideAds); // Observe the page for dynamic content loading and hide ads accordingly var observer = new MutationObserver(hideAds); observer.observe(document.body, { childList: true, subtree: true }); })();