shumin-baidu

自用,卡片样式抄改自https://greasyfork.org/zh-CN/scripts/406336

  1. // ==UserScript==
  2. // @name shumin-baidu
  3. // @description 自用,卡片样式抄改自https://greasyfork.org/zh-CN/scripts/406336
  4. // @icon http://baidu.com/favicon.ico
  5. // @namespace https://greasyfork.org/zh-CN/
  6. // @version 6.5.2
  7. // @author qianjunlang
  8. // @license MIT
  9. // @run-at document-start
  10. // @match *://*.baidu.com/s?*
  11. // @match *://*.baidu.com/baidu?*
  12. // @exclude *://baijiahao.baidu.com/*
  13. // @exclude *://m.baidu.com/*
  14. // @exclude *://wap.baidu.com/*
  15. // @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js
  16. // @grant GM_xmlhttpRequest
  17. // @connect baidu.com
  18. // @compatible edge
  19. // @compatible chrome
  20. // @compatible safari
  21.  
  22. // ==/UserScript==
  23.  
  24. function check_emp(x) {
  25. return x.length > 0;
  26. }
  27.  
  28. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*main*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  29. (function() {
  30. /* global $ */
  31. 'use strict';
  32. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  33.  
  34. var white_style = `
  35. #s_main, .s-top-nav, .s-hotsearch-wrapper, #content_right, #foot, #searchTag {
  36. display: none;
  37. }
  38. #container #content_left {
  39. width: 1000px !important;
  40. }
  41. @media screen and (min-width: 1921px) {
  42. #container.sam_newgrid {
  43. padding-left: 0 !important;
  44. width: 1000px !important;
  45. }
  46. .wrapper_new #s_tab.s_tab .s_tab_inner {
  47. padding-left: 0 !important;
  48. margin-left: -36px;
  49. }
  50. .wrapper_new #head .s_form:not(div#s_fm.s_form), .s-isindex-wrap {
  51. margin-left: -60px !important;
  52. }
  53. .wrapper_new #s_tab, #page > div, #ent_sug {
  54. width: 1000px !important;
  55. }
  56. .foot-container_2X1Nt div {
  57. width: 1000px !important;
  58. }
  59. }
  60. .new-pmd.c-container, #container #content_left .result-op, #container #content_left .result {
  61. width: 980px !important;
  62. }
  63. .new-pmd .c-span12 {
  64. width: 970px !important;
  65. }
  66. .new-pmd .c-span9 {
  67. width: 820px !important;
  68. }
  69. #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 {
  70. text-decoration: none !important;
  71. line-height: 1.3 !important
  72. }
  73. .nums, .new_search_tool_conter {
  74. width: 1000px !important;
  75. }
  76. #container.sam_newgrid {
  77. margin-left: unset !important;
  78. margin: 0 auto !important;
  79. }
  80. #container #content_left .result-op, #container #content_left .result {
  81. border-radius: 10px !important;
  82. box-shadow: 0 0 6px #eeeeff;
  83. border-left: 1px solid #eeeeee;
  84. padding: 10px 10px 15px 20px !important;
  85. transition: margin-bottom 0.6s, padding-bottom 0.6s, box-shadow 0.2s;
  86. }
  87. #container #content_left .result-op:hover, #container #content_left .result:hover {
  88. box-shadow: 1px 1px 10px #cccccc;
  89. border-radius: 0;
  90. }
  91. .new-pmd .c-border {
  92. box-shadow: unset !important
  93. }
  94. .wrapper_new #s_tab, #page > div, #ent_sug {
  95. padding-left: 0 !important;
  96. width: 1080px;
  97. margin: 0 auto !important;
  98. }
  99. #ent_sug {
  100. margin-top: 140px !important;
  101. }
  102. #help {
  103. display: block;
  104. width: 1080px;
  105. margin: 0 auto;
  106. float: unset !important;
  107. padding-left: unset !important;
  108. }
  109. #head .head_wrapper {
  110. width: 1080px;
  111. margin: 0 auto !important;
  112. }
  113. .wrapper_new #head .s_form:not(div#s_fm.s_form), .s-isindex-wrap {
  114. margin-left: 0;
  115. }
  116. .wrapper_new #head .s_form {
  117. padding-left: 0 !important;
  118. }
  119. .slowmsg1 {
  120. left: 400px !important;
  121. top: 120px !important;
  122. box-shadow: none !important;
  123. border: none !important;
  124. background: none !important;
  125. }
  126. div[class^="re-box_"] {
  127. box-shadow: none !important;
  128. }
  129. `;
  130. var style_tag = document.createElement('style');
  131. style_tag.innerHTML = white_style;
  132.  
  133. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  134. //调用全局变量的函数写在main内部
  135.  
  136. function get_s_wd(){
  137. var wd = "NONE"
  138. var qry = window.location.search.substring(1);
  139. var vals = qry.split('&');
  140. for(var i in vals){
  141. var pair = vals[i].split('=');
  142. if(pair[0] == "wd") wd = pair[1];
  143. }
  144.  
  145. wd = wd.replace(/%20/g,'+');
  146. wd = wd.split('+').filter(check_emp).join('+');
  147.  
  148. try{
  149. if(vals.length > 1) window.history.replaceState(null, null, 'https://' + window.location.hostname + '/s?wd=' + wd);
  150. }catch(error){}
  151.  
  152. return wd;
  153. }
  154. function go_elsewhere(){
  155. var wd = get_s_wd();
  156.  
  157. $("#u a.toindex").attr('href',"https://startpage.com/do/search?q="+ wd);
  158.  
  159. $("#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");
  160.  
  161. $("#result_logo").attr('href',"https://wap.baidu.com/s?pu=sz%401321_480&word="+ wd);
  162.  
  163. $("#user").attr('href','https://www.google.com/search?q='+ wd);
  164. $('#u a.lb').attr('href','https://encrypted.google.com/search?q='+ wd);
  165. }
  166. function fresh_page(){
  167.  
  168. document.head.appendChild(style_tag);
  169.  
  170. go_elsewhere();
  171.  
  172. for(let it of $('h3 > a'))
  173. try{
  174. GM_xmlhttpRequest({
  175. extData: 'https://www.baidu.com/',
  176. url: it.href+'&wd=&eqid=',
  177. headers: {"Accept": "*/*", "Referer": 'https://www.baidu.com/'},
  178. method: "GET",
  179. timeout: 100,
  180. onreadystatechange: (response)=>{
  181. if(response.responseText) {
  182. it.href = (/URL='([^']+)'/ig).exec(response.responseText)[1];
  183. return
  184. }
  185. }
  186. });
  187. }catch(error){}
  188. }
  189.  
  190. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  191. //一次性操作合集
  192.  
  193. fresh_page();
  194. $(document).ready( () => {
  195.  
  196. document.getElementById("head").style.borderBottom="1px solid #eee";
  197. document.getElementById("head").style.boxShadow="none";
  198. document.getElementById("head").style.height="50px";
  199. document.getElementById("form").style.marginTop="5px";
  200. document.getElementById("u").style.marginTop="-5px";
  201. document.getElementById("result_logo").style.marginTop="5px";
  202.  
  203. if( $("#user").length>0 ){
  204. $('#u a.pf').before( $('#user') );
  205. $("#u a.toindex").before( $('#user') );
  206.  
  207. $(".s-top-img-wrapper img").attr("src","https://www.google.com/favicon.ico");
  208. $(".s-top-username").text("Google");
  209. }
  210. if( $("#u a.lb").length>0 ){
  211. $('#u a.pf').before( $('#u a.lb') );
  212. $("#u a.toindex").before( $('#u a.lb') );
  213.  
  214. $('#u a.lb').css({"width": 60+"px",})
  215. $('#u a.lb').attr('onclick',';');
  216. $('#u a.lb').text("Google");
  217. }
  218. $("#u a.pf").text("> DuckDuckGo");
  219. $("#u a.toindex").text("=> StartPage");
  220.  
  221. $('#u a.pf').bind("click", () => { javascript:location.href=$('#u a.pf').attr('href'); });
  222. $(".bdpfmenu").remove();
  223.  
  224. go_elsewhere();
  225.  
  226. //$("#content_right").remove();
  227.  
  228. //$(".index-logo-src").attr('src','https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png')
  229. //$(".index-logo-srcnew").attr('src','https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png')
  230. //$(".index-logo-peak").attr('src','https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png')
  231. })
  232.  
  233. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  234. //一旦页面发生改变,立刻补救
  235. document.addEventListener ("DOMContentLoaded", kill_baidu);
  236. window.addEventListener('popstate', kill_baidu);
  237. window.onhashchange = kill_baidu();
  238.  
  239. function kill_baidu(){
  240. unsafeWindow.$(document).ajaxSuccess(function(e, xhr, opt) { // Microsoft Edge 和 Safari 不支持 $(document).ajaxSuccess()
  241.  
  242. fresh_page();
  243.  
  244. $('#content_left>div').has('span:contains("广告")').remove();
  245. setTimeout(function () { $('.c-container').has('.f13>span:contains("广告")').remove(); }, 2100); // 去除顽固性的延迟加载广告,一般延迟2秒左右。例如搜索“淘宝”,当页面加载完毕之后在搜索结果最前或最后会再插入一个广告。
  246. });
  247. }
  248. })();