// ==UserScript== // @name 隐藏b站视频详情页右侧的"活动推广"和"大家围观的直播" // @name:en Hide the promotion on the right side of Bilibili's video details page // @namespace http://tampermonkey.net/ // @version 0.1.3 // @description Hide specified Bilibili elements using MutationObserver // @description:en Hide specified Bilibili elements using MutationObserver // @author aspen138 // @match *://www.bilibili.com/video/* // @grant none // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; // Function to change the specified elements' background to white, prevent clicks, and disable hover effects function whiteOutElements() { var adBanner = document.getElementById('right-bottom-banner'); var liveCard = document.querySelector('.pop-live-small-mode.part-undefined'); const preventClicksAndHideElementStyles = (element) => { element.style.background = 'white'; element.style.color = 'white'; // Hides text element.style.pointerEvents = 'none'; // Disables mouse events including hover and clicks // Hide children elements by iterating through them Array.from(element.children).forEach(child => { child.style.visibility = 'hidden'; preventClicksAndHideElementStyles(child); // Apply recursively to child elements }); }; if (adBanner) { preventClicksAndHideElementStyles(adBanner); } if (liveCard) { preventClicksAndHideElementStyles(liveCard); } } // Create a MutationObserver to watch for changes in the DOM var observer = new MutationObserver(function(mutationsList) { for (var mutation of mutationsList) { if (mutation.type === 'childList') { whiteOutElements(); // Apply changes when new nodes are added } } }); observer.observe(document.body, { childList: true, subtree: true }); whiteOutElements(); // Initial application of the changes })();