// ==UserScript==
// @name shumin-baidu
// @description 自用,卡片样式抄改自https://greasyfork.org/zh-CN/scripts/406336
// @icon http://baidu.com/favicon.ico
// @namespace https://greasyfork.org/zh-CN/
// @version 6.5.2
// @author qianjunlang
// @license MIT
// @run-at document-start
// @match *://*.baidu.com/s?*
// @match *://*.baidu.com/baidu?*
// @exclude *://baijiahao.baidu.com/*
// @exclude *://m.baidu.com/*
// @exclude *://wap.baidu.com/*
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js
// @grant GM_xmlhttpRequest
// @connect baidu.com
// @compatible edge
// @compatible chrome
// @compatible safari
// ==/UserScript==
function check_emp(x) {
return x.length > 0;
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*main*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
(function() {
/* global $ */
'use strict';
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
var white_style = `
#s_main, .s-top-nav, .s-hotsearch-wrapper, #content_right, #foot, #searchTag {
display: none;
}
#container #content_left {
width: 1000px !important;
}
@media screen and (min-width: 1921px) {
#container.sam_newgrid {
padding-left: 0 !important;
width: 1000px !important;
}
.wrapper_new #s_tab.s_tab .s_tab_inner {
padding-left: 0 !important;
margin-left: -36px;
}
.wrapper_new #head .s_form:not(div#s_fm.s_form), .s-isindex-wrap {
margin-left: -60px !important;
}
.wrapper_new #s_tab, #page > div, #ent_sug {
width: 1000px !important;
}
.foot-container_2X1Nt div {
width: 1000px !important;
}
}
.new-pmd.c-container, #container #content_left .result-op, #container #content_left .result {
width: 980px !important;
}
.new-pmd .c-span12 {
width: 970px !important;
}
.new-pmd .c-span9 {
width: 820px !important;
}
#container .c-container h3.t > a:first-child, #container .c-container h3.t > a:first-child em, #container .c-container .c-title > a:first-child, #container .c-container .c-title > a:first-child em {
text-decoration: none !important;
line-height: 1.3 !important
}
.nums, .new_search_tool_conter {
width: 1000px !important;
}
#container.sam_newgrid {
margin-left: unset !important;
margin: 0 auto !important;
}
#container #content_left .result-op, #container #content_left .result {
border-radius: 10px !important;
box-shadow: 0 0 6px #eeeeff;
border-left: 1px solid #eeeeee;
padding: 10px 10px 15px 20px !important;
transition: margin-bottom 0.6s, padding-bottom 0.6s, box-shadow 0.2s;
}
#container #content_left .result-op:hover, #container #content_left .result:hover {
box-shadow: 1px 1px 10px #cccccc;
border-radius: 0;
}
.new-pmd .c-border {
box-shadow: unset !important
}
.wrapper_new #s_tab, #page > div, #ent_sug {
padding-left: 0 !important;
width: 1080px;
margin: 0 auto !important;
}
#ent_sug {
margin-top: 140px !important;
}
#help {
display: block;
width: 1080px;
margin: 0 auto;
float: unset !important;
padding-left: unset !important;
}
#head .head_wrapper {
width: 1080px;
margin: 0 auto !important;
}
.wrapper_new #head .s_form:not(div#s_fm.s_form), .s-isindex-wrap {
margin-left: 0;
}
.wrapper_new #head .s_form {
padding-left: 0 !important;
}
.slowmsg1 {
left: 400px !important;
top: 120px !important;
box-shadow: none !important;
border: none !important;
background: none !important;
}
div[class^="re-box_"] {
box-shadow: none !important;
}
`;
var style_tag = document.createElement('style');
style_tag.innerHTML = white_style;
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//调用全局变量的函数写在main内部
function get_s_wd(){
var wd = "NONE"
var qry = window.location.search.substring(1);
var vals = qry.split('&');
for(var i in vals){
var pair = vals[i].split('=');
if(pair[0] == "wd") wd = pair[1];
}
wd = wd.replace(/%20/g,'+');
wd = wd.split('+').filter(check_emp).join('+');
try{
if(vals.length > 1) window.history.replaceState(null, null, 'https://' + window.location.hostname + '/s?wd=' + wd);
}catch(error){}
return wd;
}
function go_elsewhere(){
var wd = get_s_wd();
$("#u a.toindex").attr('href',"https://startpage.com/do/search?q="+ wd);
$("#u a.pf").attr('href',"https://duckduckgo.com/?q="+ wd + "&kp=-2&kai=-1&kn=1&kaj=m&kae=c&km=m&k18=1&kg=p&kz=1&kv=1&ks=t&kw=w&kj=6e8a6c&kx=ff4b2b&k7=fffae2&k8=000000&k9=2a6fff&kaa=7d39b3&k21=fffffe");
$("#result_logo").attr('href',"https://wap.baidu.com/s?pu=sz%401321_480&word="+ wd);
$("#user").attr('href','https://www.google.com/search?q='+ wd);
$('#u a.lb').attr('href','https://encrypted.google.com/search?q='+ wd);
}
function fresh_page(){
document.head.appendChild(style_tag);
go_elsewhere();
for(let it of $('h3 > a'))
try{
GM_xmlhttpRequest({
extData: 'https://www.baidu.com/',
url: it.href+'&wd=&eqid=',
headers: {"Accept": "*/*", "Referer": 'https://www.baidu.com/'},
method: "GET",
timeout: 100,
onreadystatechange: (response)=>{
if(response.responseText) {
it.href = (/URL='([^']+)'/ig).exec(response.responseText)[1];
return
}
}
});
}catch(error){}
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//一次性操作合集
fresh_page();
$(document).ready( () => {
document.getElementById("head").style.borderBottom="1px solid #eee";
document.getElementById("head").style.boxShadow="none";
document.getElementById("head").style.height="50px";
document.getElementById("form").style.marginTop="5px";
document.getElementById("u").style.marginTop="-5px";
document.getElementById("result_logo").style.marginTop="5px";
if( $("#user").length>0 ){
$('#u a.pf').before( $('#user') );
$("#u a.toindex").before( $('#user') );
$(".s-top-img-wrapper img").attr("src","https://www.google.com/favicon.ico");
$(".s-top-username").text("Google");
}
if( $("#u a.lb").length>0 ){
$('#u a.pf').before( $('#u a.lb') );
$("#u a.toindex").before( $('#u a.lb') );
$('#u a.lb').css({"width": 60+"px",})
$('#u a.lb').attr('onclick',';');
$('#u a.lb').text("Google");
}
$("#u a.pf").text("> DuckDuckGo");
$("#u a.toindex").text("=> StartPage");
$('#u a.pf').bind("click", () => { javascript:location.href=$('#u a.pf').attr('href'); });
$(".bdpfmenu").remove();
go_elsewhere();
//$("#content_right").remove();
//$(".index-logo-src").attr('src','https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png')
//$(".index-logo-srcnew").attr('src','https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png')
//$(".index-logo-peak").attr('src','https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png')
})
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//一旦页面发生改变,立刻补救
document.addEventListener ("DOMContentLoaded", kill_baidu);
window.addEventListener('popstate', kill_baidu);
window.onhashchange = kill_baidu();
function kill_baidu(){
unsafeWindow.$(document).ajaxSuccess(function(e, xhr, opt) { // Microsoft Edge 和 Safari 不支持 $(document).ajaxSuccess()
fresh_page();
$('#content_left>div').has('span:contains("广告")').remove();
setTimeout(function () { $('.c-container').has('.f13>span:contains("广告")').remove(); }, 2100); // 去除顽固性的延迟加载广告,一般延迟2秒左右。例如搜索“淘宝”,当页面加载完毕之后在搜索结果最前或最后会再插入一个广告。
});
}
})();