FocusNinja:Bilibili, YouTube, and Zhihu Homepage Content Blocker B站油管知乎首页内容屏蔽器

Hide specific elements on Bilibili, YouTube, and Zhihu homepages

질문, 리뷰하거나, 이 스크립트를 신고하세요.
// ==UserScript==
// @name         FocusNinja:Bilibili, YouTube, and Zhihu Homepage Content Blocker B站油管知乎首页内容屏蔽器
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Hide specific elements on Bilibili, YouTube, and Zhihu homepages
// @author       Siyuan
// @match        *://*.bilibili.com/*
// @match        *://*.youtube.com/*
// @match        *://*.zhihu.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to hide elements by class name
    function hideElementsByClassName(className) {
        const elements = document.getElementsByClassName(className);
        for (let element of elements) {
            element.style.display = 'none'; // Hide the element
        }
    }

    // Function to continuously hide elements for dynamic content
    function continuouslyHide(className) {
        new MutationObserver(() => {
            hideElementsByClassName(className);
        }).observe(document.body, {childList: true, subtree: true});
    }

    // Check if it's Bilibili, YouTube, or Zhihu and act accordingly
    // Check if it's Bilibili, YouTube, or Zhihu and act accordingly
if (window.location.hostname.includes('bilibili.com')) {
    window.addEventListener('load', function() {
        hideElementsByClassName('recommend-list-v1');
        hideElementsByClassName('container is-version8');
    });
} else if (window.location.hostname.includes('youtube.com')) {
    continuouslyHide('style-scope ytd-rich-grid-renderer');
} else if (window.location.hostname.includes('zhihu.com')) {
    continuouslyHide('Card TopstoryItem TopstoryItem-isRecommend');
};

})();