Zhihu: Hide Garbage

Hide spam content under Zhihu questions.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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));
})();