// ==UserScript== // @name 知乎屏蔽盐选 // @namespace https://github.com/KingCheni/Zhihu-Block-YanXuan // @version 1.1 // @description 一键屏蔽知乎的盐选内容 // @author KingChen // @match https://*.zhihu.com/* // @grant none // @require https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js // @downloadURL none // ==/UserScript== (function() { 'use strict'; let zhihu = {}; zhihu.init = () => { const STYLE = ` `; const HTML = `
0
`; $("head").append(STYLE); $("body").append(HTML); } zhihu.setTipValue = () => { let value = parseInt($(".helper-tip").attr("data-value")); value++; $(".helper-tip").attr("data-value", value); $(".helper-tip").text(value); } zhihu.blockFunction = (obj) => { zhihu.setTipValue(); $(obj.this).attr("data-hidden", "true"); $(obj.this).hide() console.log($(obj.this)); } zhihu.match = (obj) => { if (obj.fullMatch) { if (obj.text === obj.value) { zhihu.blockFunction(obj); } } else { if (obj.text.indexOf(obj.value) != -1) { zhihu.blockFunction(obj); } } } zhihu.blockAccount = (obj) => { obj.text = $(obj.this).find(".UserLink-link").text(); obj.fullMatch = obj.fullMatch || false; zhihu.match(obj); } zhihu.blockTag = (obj) => { obj.text = $(obj.this).find(".KfeCollection-OrdinaryLabel-content").text() obj.fullMatch = obj.fullMatch || false; zhihu.match(obj); } zhihu.clear = () => { $(".Card").find(".List-item").each(function() { const tagValue = decodeURIComponent("%E7%9B%90%E9%80%89"); const username = "盐选"; if ($(this).attr("data-hidden") !== "true") { zhihu.blockTag({ this: this, value: tagValue }) zhihu.blockAccount({ this: this, value: username }) } }) } zhihu.timer = setInterval(function() { if ($(".Card").find(".List-item").length > 0) { zhihu.clear(); clearInterval(zhihu.timer); } }, 1000) zhihu.onMouseScroll = (e) => { //e.preventDefault(); var wheel = e.originalEvent.wheelDelta || -e.originalEvent.detail; var delta = Math.max(-1, Math.min(1, wheel)); if (delta < 0) { //console.log('向下滚动'); zhihu.clear(); } else { //console.log('向上滚动'); } } $(document).on('mousewheel DOMMouseScroll', zhihu.onMouseScroll); zhihu.init(); })();