// ==UserScript== // @name 真·知乎屏蔽 Truly Zhihu Shield // @namespace https://github.com/Virtual-Dimension/TrulyShield/blob/master/TrulyZhihuShield.js // @version 0.2.2 // @description Shield information you don't want to see. // @author Ciyang // @license GPL-3.0 // @match https://www.zhihu.com/* // @match http://www.zhihu.com/* // @grant none // @downloadURL none // ==/UserScript== 'use strict'; (function () { let getContentElement = () => { return document.getElementById('root'); }; let isCard = (className) => { return className.search('NestComment') !== -1 || className.search('Card') !== -1 || className.search('List-item') !== -1 || className.search('openComment') !== -1; }; let mRequest = (method, href, fn) => { let xmlHttp = new window.XMLHttpRequest(); xmlHttp.open(method, href, true); xmlHttp.onreadystatechange = () => { if (xmlHttp.readyState === 4 && xmlHttp.status === 200) { fn(xmlHttp.responseText); } }; xmlHttp.send(); }; let userShieldMap = new Map(); let excludeEditor = () => { return window.location.href.search("www.zhihu.com/people/") !== -1 || window.location.href.search("www.zhihu.com/org/") !== -1; }; let getUserShielded = (username, href, callback) => { if (!userShieldMap.has(username)) { mRequest('get', href, (resText) => { let res = (resText.search('已屏蔽') !== -1); userShieldMap.set(username, res); callback(res); }); } else { callback(userShieldMap.get(username)); } }; let checkShielded = () => { let userList = document.getElementsByClassName('UserLink-link'); for (const user of userList) { if (user.innerText && user.href) { let card = user; while (card.id !== 'root' && (!card.className || !isCard(card.className))) { card = card.parentElement; } if (card.id !== 'root') { ((userElement, cardElement) => { let url = new URL(userElement.href, window.location.href); getUserShielded(userElement.innerText, url.href, res => { if (res) { cardElement.innerHTML = ['