百度搜索框又又又加了广告,,写个油猴脚本来屏蔽
自己写一个油猴脚本,清空百度搜索框恶心的新闻广告
·
百度搜索框又又又加了广告,操作太恶心人了,怎么办?
自己动手写了个油猴脚本屏蔽掉吧,这些垃圾广告。
1.第一步,安装油猴
是的 就是这个篡改猴插件,没安装的去应用市场安装
2. 已经开发完成后上传了市场,不想自己研究的直接去油猴脚本市场搜索
3. 点击安装即可使用。
下面是源码:
Github: https://github.com/zuiyuewentian/ClearBaiduAd
// ==UserScript==
// @name 清空百度搜索框恶心的新闻广告
// @namespace https://github.com/zuiyuewentian/ClearBaiduAd
// @version 0.1
// @description 在访问百度时,将搜索框的placeholder清空
// @author chen cheng
// @match *://*.baidu.com
// @grant none
// @license Apache-2.0
// @downloadURL https://update.greasyfork.org/scripts/521469/%E6%B8%85%E7%A9%BA%E7%99%BE%E5%BA%A6%E6%90%9C%E7%B4%A2%E6%A1%86%E6%81%B6%E5%BF%83%E7%9A%84%E6%96%B0%E9%97%BB%E5%B9%BF%E5%91%8A.user.js
// @updateURL https://update.greasyfork.org/scripts/521469/%E6%B8%85%E7%A9%BA%E7%99%BE%E5%BA%A6%E6%90%9C%E7%B4%A2%E6%A1%86%E6%81%B6%E5%BF%83%E7%9A%84%E6%96%B0%E9%97%BB%E5%B9%BF%E5%91%8A.meta.js
// ==/UserScript==
(function() {
'use strict';
// 封装一个处理函数,用来清空 placeholder
function clearPlaceholder() {
// 查找所有 input 元素
const inputElements = document.querySelectorAll('input');
// 遍历所有的 input 元素
inputElements.forEach(function(input) {
// 如果 input 元素的 id 为 'kw',清空 placeholder
if (input.id === 'kw' ||input.id==='index-kw'||input.name=='wd'&& input.placeholder !== '') {
input.placeholder = '';
}
});
}
// 确保在页面加载完成后执行
window.addEventListener('load', function() {
clearPlaceholder(); // 第一次处理
// 不同网络状态可以导致不能结果
setTimeout(function() {
clearPlaceholder();
}, 30);
setTimeout(function() {
clearPlaceholder();
}, 100);
setTimeout(function() {
clearPlaceholder();
}, 300);
});
})();
更多推荐
所有评论(0)