Zhihu: Hide Garbage

Hide spam content under Zhihu questions.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name                Zhihu: Hide Garbage
// @name:zh-CN          知乎: 隐藏垃圾
// @description         Hide spam content under Zhihu questions.
// @description:zh-CN   隐藏 知乎 问题下的垃圾内容。
// @author              dawn-lc
// @namespace           https://github.com/dawn-lc
// @license             MIT
// @icon                https://static.zhihu.com/heifetz/favicon.ico
// @match               *://*.zhihu.com/question/*
// @grant               none
// @version             1.0.4
// ==/UserScript==
(function() {
    function debounce(fn, delay, { immediate = false } = {}) {
        let timer = null;
        const debounced = function(...args) {
            const callNow = immediate && !timer;
            if (timer) {
                clearTimeout(timer);
            }
            timer = setTimeout(() => {
                timer = null;
                if (!immediate) {
                    fn.apply(this, args);
                }
            }, delay);
            if (callNow) {
                fn.apply(this, args);
            }
        };
        debounced.cancel = () => {
            if (timer) {
                clearTimeout(timer);
                timer = null;
            }
        };
        return debounced;
    }
    window.addEventListener("scroll", debounce(() => {
        [...document.querySelectorAll('.List-item')].filter(i => i.querySelector('[class*="KfeCollection"]') != null).forEach(i => i.style.setProperty('display', 'none'));
        [...document.querySelectorAll('.Pc-word-new')].forEach(i => i.style.setProperty('display', 'none'));
    }, 1000));
})();