百度搜索优化sp

Tampermonkey脚本,屏蔽百度推广和各种广告+页面样式美化+url重定向

  1. // ==UserScript==
  2. // @name 百度搜索优化sp
  3. // @namespace bdso_sp
  4. // @description Tampermonkey脚本,屏蔽百度推广和各种广告+页面样式美化+url重定向
  5. // @update-url https://gf.qytechs.cn/zh-CN/users/218062-vizo
  6. // @author vizo
  7. // @version 3.0.2
  8. // @require https://lib.baomitu.com/jquery/3.6.0/jquery.min.js
  9. // @include https://www.baidu.com/s*
  10. // @run-at document-start
  11. // @grant GM_addStyle
  12. // @grant GM_addElement
  13. // @grant GM_xmlhttpRequest
  14. // @connect *
  15. // @license MIT
  16. // ==/UserScript==
  17.  
  18. let bdcss = `
  19. body,
  20. div,
  21. th,
  22. td,
  23. .p1,
  24. .p2,
  25. h1,
  26. h2,
  27. h3,
  28. h4,
  29. h5,
  30. h6,
  31. a {
  32. font-family: sans-serif,"Helvetica Neue",Helvetica,"PingFang SC","Microsoft YaHei","Hiragino Sans GB",Arial;
  33. }
  34. h1,
  35. h2,
  36. h3,
  37. h4,
  38. h5,
  39. h6 {
  40. font-weight: normal !important;
  41. }
  42. .c-tools,
  43. .to_tieba,
  44. .res_top_banner,
  45. .op-soft-normal-tip,
  46. .hint_right_middle,
  47. .rrecom-container,
  48. .hint_common_restop,
  49. .rrecom-btn-parent,
  50. .c-pingjia,
  51. .ad-block,
  52. #m2c69bdd0,
  53. #imsg,
  54. #rs_top_new,
  55. #foot,
  56. #page .fk,
  57. #content_left .leftBlock,
  58. #content_left > table,
  59. #content_right .c-gray,
  60. #content_right .hint_right_top,
  61. #content_right .opr-toplist-info,
  62. #content_right table table {
  63. display: none !important;
  64. }
  65. a.m {
  66. box-shadow: -9px 0px 0 0px #fff;
  67. color: #fff;
  68. pointer-events: none;
  69. }
  70. .container_l {
  71. width: 100%;
  72. }
  73. #wrapper.wrapper_l {
  74. overflow: hidden;
  75. }
  76. #head .headBlock {
  77. margin: 4px 0 10px 0 !important;
  78. }
  79. #head .headBlock a:hover {
  80. text-decoration: underline !important;
  81. }
  82. #head .headBlock .hint_toprq_tips {
  83. width: 730px;
  84. margin: 0 auto;
  85. }
  86. body .result-molecule {
  87. width: 748px !important;
  88. margin: 10px auto 10px auto !important;
  89. padding: 0 !important;
  90. }
  91. #form {
  92. float: none !important;
  93. margin: 0 auto !important;
  94. width: 740px;
  95. display: block;
  96. padding-top: 16px;
  97. padding-left: 0;
  98. transform: translateX(-6px);
  99. }
  100. #form .s_ipt_wr {
  101. width: 616px !important;
  102. height: 36px;
  103. border: 1px solid #c4c7ce;
  104. border-radius: 0;
  105. }
  106. #form .s_btn {
  107. height: 38px !important;
  108. line-height: 40px;
  109. font-size: 16px;
  110. display: block;
  111. border-radius: 0;
  112. background-color: #07e;
  113. }
  114.  
  115. #head.fix-head #form {
  116. padding-top: 8px;
  117. }
  118. #head.fix-head #form #xyb_goo_so_btn {
  119. top: 16px;
  120. }
  121. #head.fix-head #form .bdsug-new {
  122. top: 49px;
  123. }
  124.  
  125. .soutu-env-result .soutu-layer,
  126. .soutu-env-imgresult .soutu-layer {
  127. width: 748px !important;
  128. }
  129. .soutu-layer .soutu-url-btn {
  130. width: 186px !important;
  131. }
  132. .wrapper_l #kw {
  133. height: 36px;
  134. font: 16px/36px Microsoft YaHei;
  135. width: 570px !important;
  136. margin: 0 !important;
  137. padding-left: 7px;
  138. }
  139. .content_none {
  140. width: 748px;
  141. padding: 40px 0;
  142. margin: 0 auto;
  143. }
  144. .search_tool_conter {
  145. margin: 0 auto !important;
  146. }
  147. .nums {
  148. margin: 0 auto !important;
  149. }
  150. #s_tab {
  151. width: 717px;
  152. margin: 0 auto;
  153. position: relative;
  154. padding: 72px 0 0 0 !important;
  155. overflow: visible !important;
  156. border-bottom: none !important;
  157. opacity: 0;
  158. animation: fadeIn 1s both;
  159. }
  160. .s_form::after,
  161. .s_tab::after {
  162. visibility: visible !important;
  163. }
  164. #s_tab::after {
  165. content: '';
  166. width: 5000px;
  167. height: 1px;
  168. background: #e1e1e1;
  169. position: absolute;
  170. left: -2500px;
  171. bottom: -2px;
  172. z-index: 3;
  173. }
  174. .head_nums_cont_inner {
  175. overflow-x: hidden !important;
  176. opacity: 0;
  177. animation: fadeIn 1s both;
  178. }
  179.  
  180. #content_right {
  181. display: none !important;
  182. }
  183.  
  184. body {
  185. background: #f9f9f9;
  186. background-attachment: fixed;
  187. }
  188. a {
  189. text-decoration: none !important;
  190. color: #07e;
  191. }
  192. a:hover {
  193. color: #07e;
  194. }
  195. a em {
  196. text-decoration: none;
  197. }
  198.  
  199. #u,
  200. #head,
  201. #tool,
  202. #search,
  203. #foot {
  204. font-size: 14px;
  205. }
  206. #form .s_ipt_wr {
  207. width: 625px;
  208. }
  209.  
  210. body .wrapper_new #form .bdsug-new {
  211. width: 615px;
  212. border: 1px solid #c4c5c6 !important;
  213. border-radius: 0;
  214. top: 57px;
  215. }
  216. .wrapper_new #form .bdsug-new ul {
  217. border-top: 0 !important;
  218. }
  219. #s_tab b {
  220. border-bottom: 3px #07e solid;
  221. color: #07e;
  222. }
  223.  
  224. #rs {
  225. width: 690px;
  226. padding: 10px 20px 10px;
  227. margin: 10px auto 10px auto !important;
  228. background-color: #fff;
  229. border-radius: 2px;
  230. box-shadow: 0 0 5px #dbdbdb;
  231. opacity: 0;
  232. overflow: hidden;
  233. animation: fadeInUp 0.35s both;
  234. }
  235. #rs a:hover {
  236. text-decoration: underline !important;
  237. }
  238. #rs .tt {
  239. border-bottom: 1px solid #ddd;
  240. }
  241. #rs th {
  242. width: 300px;
  243. font-size: 15px;
  244. padding-top: 5px;
  245. padding-left: 50px;
  246. }
  247. #container {
  248. margin: 0 auto !important;
  249. }
  250. #content_left {
  251. width: 748px !important;
  252. }
  253. #content_left td a:hover,
  254. #content_left .c-row a:hover {
  255. text-decoration: underline !important;
  256. }
  257. #wrapper_wrapper #content_left {
  258. width: 730px;
  259. padding-left: 0;
  260. float: none;
  261. margin: 0 auto !important;
  262. padding: 0 !important;
  263. opacity: 0;
  264. animation: fadeInUp 0.35s both;
  265. }
  266. #content_left > .c-container {
  267. width: 100% !important;
  268. box-sizing: border-box;
  269. margin-bottom: 10px !important;
  270. padding: 10px 15px 10px 15px;
  271. background-color: #fff;
  272. border-radius: 5px;
  273. box-shadow: 0 0 5px #d3d5d7;
  274. }
  275. #content_left article[class*="open-source-software-card_"],
  276. #content_left article[class*="aladdin_"] {
  277. padding: 0;
  278. box-shadow: none;
  279. }
  280. #content_left .c-container h3 {
  281. padding-bottom: 5px;
  282. margin-bottom: 8px;
  283. font-weight: bold;
  284. border-bottom: 1px solid #ddd;
  285. }
  286. .c-container h3 a {
  287. position: relative;
  288. display: inline-block;
  289. font-size: 18px;
  290. font-family: Helvetica Neue, sans-serif, Microsoft YaHei, helvetica, arial;
  291. }
  292. #content_left .c-container h3 a.favurl {
  293. background-position: 0 5px;
  294. background-repeat: no-repeat;
  295. }
  296. #content_left .OP_LOG_LINK.c-text {
  297. font-size: 14px !important;
  298. vertical-align: -5px;
  299. }
  300. #content_left .OP_LOG_LINK.c-text:visited {
  301. color: #fff;
  302. }
  303. #content_left .OP_LOG_LINK.c-text:hover {
  304. color: #fff;
  305. }
  306. #content_left .c-container h3 a:hover {
  307. color: #07e;
  308. }
  309. #content_left .c-container h3 a:hover:after {
  310. left: 0;
  311. width: 100%;
  312. transition: width 0.35s;
  313. }
  314. #content_left .c-container h3 a:after {
  315. content: '';
  316. position: absolute;
  317. border-bottom: 2px solid #37e;
  318. bottom: -4px;
  319. left: 100%;
  320. width: 0;
  321. transition: width 0.35s, left 0.35s;
  322. }
  323.  
  324. #content_left .c-container h3 a {
  325. position: relative;
  326. }
  327. #content_left .c-container h3 a:visited {
  328. color: #660099;
  329. }
  330. #content_left .c-container h3 a:visited:hover:after {
  331. left: 0;
  332. width: 100%;
  333. transition: width 0.35s;
  334. }
  335. #content_left .c-container h3 a:visited:after {
  336. content: '';
  337. position: absolute;
  338. border-bottom: 2px solid #660099;
  339. bottom: -2px;
  340. left: 100%;
  341. width: 0;
  342. transition: width 0.35s, left 0.35s;
  343. }
  344.  
  345. #content_left .c-abstract {
  346. width: 100%;
  347. }
  348. #content_left .c-span18 {
  349. width: 560px;
  350. }
  351. #content_left .c-border {
  352. width: auto;
  353. box-shadow: none;
  354. }
  355.  
  356. #content_left .op-soft-btnbox .c-btn-primary {
  357. display: none;
  358. }
  359. #content_left .op-soft-btnbox a {
  360. border: 1px solid;
  361. padding: 7px;
  362. }
  363.  
  364. #content_left .op-soft-btnbox a:hover {
  365. text-decoration: none !important;
  366. background: #2c99ff;
  367. color: #fff;
  368. }
  369. #content_left .c-container .f13,
  370. #content_left .c-container .c-row,
  371. .c-abstract {
  372. font-size: 14px;
  373. line-height: 24px;
  374. }
  375. .c-border {
  376. width: 518px;
  377. padding: 9px;
  378. margin: auto;
  379. border: 1px solid #f3f3f3;
  380. border-bottom-color: #f3f3f3;
  381. border-right-color: #f3f3f3;
  382. box-shadow: 1px 2px 0px rgba(0, 0, 0, 0);
  383. }
  384. @keyframes fadeInUp {
  385. from {
  386. opacity: 0;
  387. -webkit-transform: translateY(30px);
  388. transform: translateY(30px);
  389. }
  390. to {
  391. opacity: 1;
  392. -webkit-transform: none;
  393. transform: none;
  394. }
  395. }
  396. @keyframes fadeIn {
  397. from {
  398. opacity: 0;
  399. }
  400. to {
  401. opacity: 1;
  402. }
  403. }
  404.  
  405. #page {
  406. display: block;
  407. width: 710px;
  408. height: 40px;
  409. line-height: 40px;
  410. background-color: transparent !important;
  411. padding: 5px 5px 5px 15px !important;
  412. border-radius: 3px;
  413. margin: 30px auto 80px auto !important;
  414. text-align: center;
  415. }
  416. #page a,
  417. #page strong {
  418. height: auto;
  419. box-shadow: 0 0 10px #c4c5c6;
  420. }
  421. #page .pc:hover {
  422. background: #07e;
  423. color: #07e;
  424. }
  425. #page strong .pc {
  426. background: #07e;
  427. color: #fff;
  428. }
  429. #page strong .pc:hover {
  430. background: #07e;
  431. color: #fff;
  432. }
  433.  
  434. #page a span:hover {
  435. background: #07e !important;
  436. color: #fff !important;
  437. }
  438.  
  439. #page [class*="page-inner"] {
  440. padding: 0 !important;
  441. }
  442.  
  443. #con-at .result-op {
  444. margin: 10px auto auto 10px;
  445. padding: 5px 40px 5px 20px;
  446. background: #fdfdfd;
  447. box-shadow: 0 0px 1px 0.5px #0f93d2, 0 1px 5px 0px rgba(0, 0, 0, 0.7);
  448. transition: 0.4s;
  449. }
  450.  
  451. body > .result-op {
  452. background: none !important;
  453. }
  454.  
  455. #content_left > div:not([id]) {
  456. width: 640px;
  457. margin-bottom: 10px;
  458. padding: 10px 45px;
  459. border-radius: 2px;
  460. box-shadow: 0 0 5px #c4c5c6;
  461. }
  462. .t > div:not([id]) {
  463. width: 640px;
  464. margin-bottom: 10px;
  465. padding: 10px 45px;
  466. border-radius: 3px;
  467. box-shadow: 0 0 10px #c4c5c6;
  468. }
  469.  
  470. body > div[style*='position: absolute;'],
  471. body > div[style*='position: fixed;'] {
  472. display: none !important;
  473. }
  474.  
  475. #content_left > div[style*='display:block !important'] {
  476. position: absolute !important;
  477. top: -5000px !important;
  478. display: none !important;
  479. }
  480.  
  481. .bdpage-l,
  482. .bdpage-r {
  483. width: 300px;
  484. height: 500px;
  485. overflow: hidden;
  486. cursor: pointer;
  487. position: fixed;
  488. top: 0;
  489. bottom: 0;
  490. margin: auto;
  491. }
  492. .bdpage-l.disa,
  493. .bdpage-r.disa {
  494. cursor: not-allowed;
  495. }
  496. .bdpage-l:hover,
  497. .bdpage-r:hover {
  498. background: rgba(100, 100, 100, 0.03);
  499. }
  500. .bdpage-l::before,
  501. .bdpage-r::before {
  502. content: '';
  503. width: 100px;
  504. height: 100px;
  505. border-left: 2px solid #e7e9eb;
  506. border-bottom: 2px solid #e7e9eb;
  507. position: absolute;
  508. top: 0;
  509. bottom: 0;
  510. margin: auto;
  511. }
  512. .bdpage-l:hover::before,
  513. .bdpage-r:hover::before {
  514. border-color: #fff;
  515. }
  516. .bdpage-l {
  517. left: 0;
  518. }
  519. .bdpage-l::before {
  520. left: 45%;
  521. transform: rotate(45deg);
  522. }
  523. .bdpage-r {
  524. right: 0;
  525. }
  526. .bdpage-r::before {
  527. right: 45%;
  528. transform: rotate(225deg);
  529. }
  530. #xyb_goo_so_btn {
  531. font-size: 15px;
  532. cursor: pointer;
  533. position: absolute;
  534. top: 24px;
  535. right: -68px;
  536. z-index: 5;
  537. }
  538. .dn {
  539. display: none !important;
  540. }
  541.  
  542. a.cdx_ed {
  543. position: relative;
  544. }
  545. a.cdx_ed::before {
  546. content: '已解析url';
  547. color: #ccc;
  548. font-size: 12px;
  549. width: 60px;
  550. height: 15px;
  551. line-height: 15px;
  552. text-align: left;
  553. position: absolute;
  554. top: -10px;
  555. left: 10px;
  556. z-index: 1;
  557. }
  558. .load-zp {
  559. width: 8px;
  560. height: 8px;
  561. border-radius: 55%;
  562. box-shadow: -9px -9px #098deb, 9px -9px #098deb, -9px 9px #098deb, 9px 9px #098deb;
  563. position: fixed;
  564. top: 0;
  565. right: 0;
  566. bottom: 0;
  567. left: 0;
  568. margin: auto;
  569. z-index: 5000;
  570. pointer-events: none;
  571. animation: anim1z .9s linear infinite;
  572. }
  573.  
  574. @keyframes anim1z {
  575. 100% {
  576. transform: rotate(1turn);
  577. }
  578. }
  579.  
  580. @media (max-width: 1280px) {
  581. .bdpage-l,
  582. .bdpage-r {
  583. width: 150px;
  584. }
  585. }
  586.  
  587. `
  588.  
  589. appendBdCss()
  590.  
  591. function appendBdCss() {
  592. GM_addElement('style', {
  593. textContent: bdcss,
  594. class: 'bdso444yx',
  595. })
  596. }
  597.  
  598. //导入CSS
  599.  
  600. function importCSS() {
  601. let isAddStyle = document.head.querySelector('.bdso444yx')
  602. if (!isAddStyle) {
  603. appendBdCss()
  604. }
  605. let gooSo = $('body').find('#xyb_goo_so_btn').length
  606. if (!gooSo) {
  607. $('body').find('#form').append('<a id="xyb_goo_so_btn" href="javascript:;">谷歌搜索</a>')
  608. }
  609. }
  610.  
  611. $(function() {
  612. initFunc()
  613.  
  614. try {
  615. let MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver
  616. let observer = new MutationObserver(initFunc)
  617. let wrapper = document.querySelector('#wrapper_wrapper')
  618. //动态监视DOM树的变化
  619. observer.observe(wrapper, {
  620. attributes: true,
  621. childList: true,
  622. subtree: true,
  623. })
  624. } catch (e) {}
  625.  
  626. function initFunc() {
  627. importCSS()
  628. removeADS()
  629. cdxUrl()
  630. appendElem()
  631. setPNStatus()
  632. }
  633.  
  634. // 设置a标签真实地址
  635. function cdxUrl() {
  636. $('#content_left .c-container[mu^="http"]').each((i, v) => {
  637. let tis = $(v)
  638. const murl = tis.attr('mu')
  639. const link = tis.find('.t > a')
  640. const lnkUrl = link.attr('href')
  641. if (
  642. lnkUrl !== murl
  643. && !murl.includes('baidu.com')
  644. ) {
  645. link.attr('href', murl)
  646. }
  647. })
  648. }
  649.  
  650. // 上一页下一页按钮
  651. function appendElem() {
  652. let len = $('body').find('.bdpage-l').length
  653. if (!len) {
  654. $('body').append('<div class="bdpage-l"></div><div class="bdpage-r"></div>')
  655. }
  656. }
  657. function showLoading() {
  658. $('body').append('<div class="load-zp"></div>')
  659. }
  660. function hideLoading() {
  661. $('body').find('.load-zp')?.remove()
  662. }
  663. function throttle(func, wait) {
  664. let start = 0
  665. return function(...args) {
  666. let now = Date.now()
  667. if (now - start >= wait) {
  668. func.apply(this, args)
  669. start = now
  670. }
  671. }
  672. }
  673.  
  674. // 设置上下页状态
  675. function setPNStatus() {
  676. let fkl = true
  677. let fkr = true
  678. $('#page .n').each(function() {
  679. let that = $(this)
  680. let text = that.text()
  681. if (text.includes('上一页')) {
  682. fkl = false
  683. }
  684. if (text.includes('下一页')) {
  685. fkr = false
  686. }
  687. })
  688. if (fkl) {
  689. $('body')
  690. .find('.bdpage-l')
  691. .addClass('disa')
  692. } else {
  693. $('body')
  694. .find('.bdpage-l')
  695. .removeClass('disa')
  696. }
  697. if (fkr) {
  698. $('body')
  699. .find('.bdpage-r')
  700. .addClass('disa')
  701. } else {
  702. $('body')
  703. .find('.bdpage-r')
  704. .removeClass('disa')
  705. }
  706. }
  707. function showDeferHideLoad() {
  708. showLoading()
  709. setTimeout(hideLoading, 3000)
  710. }
  711. function ckPage(type = 1) {
  712. $('#page .n').each(function() {
  713. let that = $(this)
  714. let text = that.text()
  715. if (text.includes(type === 1 ? '上一页' : '下一页')) {
  716. that[0].click()
  717. showDeferHideLoad()
  718. }
  719. })
  720. }
  721. //屏蔽广告和推广
  722. function removeADS() {
  723. let $ads = ['#content_left>div[style*="display:block !important"]', '#content_left>div:not([id])', '#content_left>#clone']
  724. let $selctor = $($ads.join())
  725. $selctor.remove()
  726.  
  727. $('#content_left .result[id=1]').each(function() {
  728. let tis = $(this)
  729. let txt = tis.find('.f13 .m').text()
  730. if (txt == '广告') {
  731. tis.remove()
  732. }
  733. })
  734. }
  735. $('body').on('click', '.bdpage-l', function() {
  736. ckPage(1)
  737. })
  738. $('body').on('click', '.bdpage-r', function() {
  739. ckPage(2)
  740. })
  741. // 点击谷歌搜索
  742. $('body').on('mousedown', '#xyb_goo_so_btn', function(e) {
  743. e.preventDefault()
  744. if (e.button === 0 || e.button === 1) {
  745. const goo = localStorage.getItem('bdso[gooUrl]') || 'https://www.google.com.hk/search?q='
  746. const wd = $('body').find('#kw').val()
  747. const kw = wd ? encodeURIComponent(wd) : wd
  748. window.open(goo + kw, '_blank')
  749. }
  750. })
  751. })

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址