Greasy Fork

删除知乎视频回答和盐选/电子书节选回答

删除知乎中包含视频回答和盐选/电子书节选的内容块

// ==UserScript==
// @name         删除知乎视频回答和盐选/电子书节选回答
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  删除知乎中包含视频回答和盐选/电子书节选的内容块
// @author       walterscott123
// @match        *://www.zhihu.com/*
// @grant        none
// @license MIT
// ==/UserScript==



(function() {
    'use strict';

    // Function to remove nodes
    function removeVideoAnswers() {
        // Select all elements with class "VideoAnswerPlayer"
        const videoPlayers = document.querySelectorAll('.VideoAnswerPlayer');

        videoPlayers.forEach(player => {
            // Find the closest parent with class "feed"
            const feedDiv = player.closest('.Feed');
            if (feedDiv) {
                // Remove the parent node from the DOM
                feedDiv.remove();
            }
        });

        const another = document.querySelectorAll('.ZVideoItem-video');
        another.forEach(player => {
            // Find the closest parent with class "feed"
            const feedDiv = player.closest('.Feed');
            if (feedDiv) {
                // Remove the parent node from the DOM
                feedDiv.remove();
            }
        });
        const anwser_from_some_book = document.querySelectorAll('.KfeCollection-OrdinaryLabel-content');

        anwser_from_some_book.forEach(player => {
            // Find the closest parent with class "feed"
            const feedDiv = player.closest('.AnswerItem');
            if (feedDiv) {
                // Remove the parent node from the DOM
                feedDiv.remove();
            }
        });
    }

    // Run the function initially
    removeVideoAnswers();

    // Observe for dynamic changes on the page (useful for infinite scrolling)
    const observer = new MutationObserver(() => {
        removeVideoAnswers();
    });

    // Observe changes to the body
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });
})();