Greasy Fork is available in English.
需要 搭配stylish插件使用,名称:百度搜索-屏蔽和优化,网址:https://userstyles.org/styles/138933/theme
当前为
// ==UserScript==
// @name 百度搜索 - 优化版
// @namespace http://tampermonkey.net/
// @version 0.2
// @description 需要 搭配stylish插件使用,名称:百度搜索-屏蔽和优化,网址:https://userstyles.org/styles/138933/theme
// @author You
// @match *www.baidu.com/s*
// @grant none
// ==/UserScript==
(function(){
"use strict";
//动态监视DOM树的变化
var observer = new MutationObserver(mutationfunc);
var wrapper = document.querySelector("#wrapper");
observer.observe(wrapper, {
"attributes": true,
"attributesFilter": ["class"],
});
//DOM加载完成后
document.ready = function(){
//将相关搜索移到上面
changeRelateSerchToTop();
//绑定快捷键
bindQuickKey();
};
function mutationfunc(){
//将相关搜索移到上面
changeRelateSerchToTop();
//隐藏广告
hideADS();
//改变ID
changID();
//关闭推广
closeCookie();
setTimeout(function(){
//隐藏广告
hideADS();
},1000);
}
})();
//隐藏广告和推广
function hideADS(){
var $ads = [
"#content_left>div[style*='display:block !important;']",
"#content_left>div:not([id])"
];
var $selctor = $( $ads.join());
$selctor.remove();
}
//改变ID
function changID(){
var $ids = [
"#content_left>div[id='1']"
];
var $selctor = $( $ids.join());
$selctor.attr("id","2");
}
//关闭百度联盟Cookie
function closeCookie(){
var cpro_url = "http://help.wangmeng.baidu.com/cpro.php";
var img = document.createElement("img");
img.src = cpro_url + "?pry=" + 1 + "&_t=" + (new Date()).getTime();
}
//将相关搜索移到上面
function changeRelateSerchToTop(){
var child = document.getElementById("rs");
var parent = document.getElementById("content_left");
parent.insertBefore(child,parent.childNodes[0]);
child.style.display="block";
$("#rs").css("margin","0px");
}
//绑定快捷键
function bindQuickKey(){
window.onkeydown = function() {
//上一页
if(event.keyCode == 37 && event.ctrlKey) {
$(".n:first").click();
}
//下一页
if(event.keyCode == 39 && event.ctrlKey) {
$(".n:last").click();
}
//搜索框
if(event.keyCode == 13 && event.ctrlKey ) {
$("#kw").select();
}
};
}