屏蔽知乎热门内容推荐

屏蔽知乎feed流的热门推荐

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         屏蔽知乎热门内容推荐
// @namespace    http://tampermonkey.net/
// @version      0.13
// @description  屏蔽知乎feed流的热门推荐
// @author       Yidadaa
// @match        https://www.zhihu.com/
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    let lastItemCount = 0;
    const selectItems = () => document.querySelectorAll('.TopstoryItem');
    const container = document.querySelector('.Topstory-mainColumn');
    const doRemove = () => {
        const newItems = selectItems();
        if (newItems.length !== lastItemCount) {
            Array.from(newItems)
                .filter(v => v.innerText.indexOf('热门内容') > -1)
                .forEach(v => v.style.display='none');
            lastItemCount = newItems.length;
        }
        const containerHeight = container.getBoundingClientRect().height;
        const windowHeight = window.innerHeight;
        if (containerHeight < windowHeight) {
            container.style.marginBottom = `${windowHeight - containerHeight + 100}px`;// 防止页面无法滚动,导致无法触发知乎刷新
        }
    };
    const oldListener = window.onscroll;
    window.onscroll = () => {
        if (!!oldListener) oldListener();
        doRemove();
    };
    const oldOnload = window.onload;
    window.onload = () => {
        if (!!oldOnload) oldOnload();
        doRemove();
    };
})();