自动在搜索条件后面增加 -csdn, 以此屏蔽csdn网站信息。只适用于google和百度的搜索页面
< google百度搜索屏蔽CSDN 피드백
2024-07-05 更新 search input 查询。
(function() { 'use strict'; const className = { "baidu":"form[action='/s'] s_ipt", "google": "form[action='/search'] textarea.gLFyf" }; const key = window.location.href.indexOf("://www.baidu.com") !== -1 ? "baidu" : "google"; const wordInput = document.querySelector(className[key]); if (wordInput) { wordInput.addEventListener("keydown", function(e) { if (e.key = 'Enter' && this.value.length > 0 && this.value.indexOf("-csdn") === -1) { this.value += " -csdn"; } }); wordInput.addEventListener("blur", function() { if (this.value.length > 0 && this.value.indexOf("-csdn") === -1) { this.value += " -csdn"; } }); wordInput.addEventListener("focus", function() { const index = this.value.indexOf(" -csdn"); if (index !== -1) { this.value = this.value.substring(0, index); } }); window.onbeforeunload = function() { const index = wordInput.value.indexOf(" -csdn"); if (index !== -1) { wordInput.value = wordInput.value.substring(0, index); } } } })();
有个小bug,把
if (e.key = 'Enter' && this.value.length > 0 && this.value.indexOf("-csdn") === -1) { ... });
中的 e.key = 'Enter' 改成 e.key === 'Enter'在google中就可以正常使用了
e.key = 'Enter'
e.key === 'Enter'
댓글을 남기려면 로그인하세요.
2024-07-05 更新 search input 查询。