// ==UserScript== // @name 极简百度首页by: yzl // @namespace http://tampermonkey.net/ // @match https://www.baidu.com/ // @version 0.5 // @description 仅适用于PC版百度首页,仅个人深入学习js所写 // @author U1iz // @icon http://res1433223.net3v.net/img/favicon.png // @grant none // @downloadURL none // ==/UserScript== (function() { //构建“存在即删除”函数 function elementRemove(element){ if(element){ element.remove(); }; }; //构建“获取元素”函数 function getElement(name,type,quantity){ var e; if(type == 'c'){ e = document.getElementsByClassName(name); if(quantity){ for(var i = 0; i < quantity; i++){ return(e[i]); }; } } else if(type == 'id') { e = document.getElementById(name); } return(e); }; //合集 function all(){ //更改主体容器类名 getElement('head_wrapper','id').className = 'head_wrapper s-isindex-wrap nologin s-ps-islite'; //移除热搜开启&关闭元素 elementRemove(getElement('set-show','c',1)); elementRemove(getElement('set-hide','c',1)); //更改全局背景色 document.body.style.backgroundColor = '#ddd'; //移除首页下方ad容器 elementRemove(document.getElementById('s-hotsearch-wrapper')); elementRemove(document.getElementById('s-top-left')); //移除首页上方导航栏 elementRemove(document.getElementById('s_top_wrap')); //移除右上用户登录入口 elementRemove(document.querySelector('.s-top-login-btn')); //移除登录界面 elementRemove(document.getElementById('TANGRAM__PSP_5__')); elementRemove(document.getElementsByClassName('pop-mask')[0]); elementRemove(document.getElementById('TANGRAM__PSP_4__foreground')); elementRemove(document.querySelector('.pass-login-pop-form')); //移除右下绝对定位二维码登录 elementRemove(getElement('s_qrcode_nologin','id')); //更改底部bgc 等于页面背景色 getElement('bottom_layer','id').style.backgroundColor = document.body.style.backgroundColor; //更改logo图标,变相禁止点击跳转 svg来自阿里妈妈图标库 getElement('lg','id').innerHTML = ''; }; all(); window.onload = function(){ console.log(getElement('s_ipt', 'c')); //设置定时器,每1s执行一次 setInterval(function(){ all(); },1000) }; })();