banner
Vinking

Vinking

你写下的每一个BUG 都是人类反抗被人工智能统治的一颗子弹

Optimize Baidu search results

Recently, I reinstalled the operating system on a friend's computer. When I downloaded the original software, I found that the ads on Baidu were really, really excessive. Even after installing an ad filtering script, there were still some targeted promotions based on search keywords.

Non-official download link

These promotions take up a huge space, and to see the content below, you have to scroll the mouse a few more times. Additionally, there are ads like related videos and bestsellers online, which can't be said to be unnecessary but are completely useless. Fortunately, the ad filtering script I installed earlier has a custom style feature that allows you to use CSS to block those promotions. After a night of searching for various strange keywords, I obtained the following blocking list for the corresponding promotional ads, which can simply be pasted into the custom style box of the script and saved.

You can find the same rules I am using at the link below:

/* Updated on 2024.8.27 */

/* Hide all useless Baidu services */
div[tpl*="game"],
div[tpl="pc-soft-accurate"],
div[tpl="pc-soft-fs"],
div[tpl="se_st_com_abstract"],
div[tpl="short_video_pc"],
div[tpl="se_st_single_video_zhanzhang"],
div[tpl="exactqa"],
div[tpl="yl-vd-basis"],
div[tpl="text04"],
div[tpl="b2b_industry_zk"],
div[tpl="sp_hot_sale"],
div[tpl="ads_b2c_universal_card"],
div[tpl="news-realtime"],
div[tpl="jy_course_and_org_pc"],
div[tpl="poi_mapdots"],
div[tpl="ms_weak_kefu"],
div[tpl="jr_stock"],
div[tpl="job3"],
div[tpl="zk-header"],
div[tpl="short_video"],
div[tpl="video_vast"],
div[tpl="med_disease_kg_collection"],
div[tpl="ask_doctor"],
div[tpl="med_qa"],
div[tpl="b2b_factory2"],
div[tpl="bjh_addressing"],
div[tpl="recommend_list"],
div[tpl="kaifa_pc_blog_weak"],
div[class*="video-container"],
div[tpl="vmp_zxenterprise_new"],
div[tpl="open_source_software"],
div[tpl="pc-soft-app"],
div[tpl="vmp_newproject_new"],
div[tpl="wenda_abstract_pc"],
div[tpl="aladdin_wenku_pc_new"] > div,
div[tql*="wenku"],
div[tpl="jr_stock_comment_san"],
div[tpl="ybb"],
div[tpl="med_disease_kg_collection_san"],
div[tpl="live_converge_san"],
div[tpl="sp_purc_pc"],
div[tpl="ins_application_card"],
div[tpl="generaltable"] {
  margin: 0 0 10px !important;
  padding: 10px 20px !important;

  & > * {
    display: none !important;
  }

  &::after {
    content: "Matched rule:" attr(tpl);
    color: #a9a9a9;
    text-align: right;
    width: 50%;
  }

  &::before {
    content: "Result has been hidden";
    width: 50%;
  }
}

/* Hide certain Baidu components */
#wrapper #content_left .op-soft-title a:hover:after,
#wrapper #content_left .result a:hover:after,
#wrapper #content_left .result-op a:hover:after,
#wrapper #content_left > .c-container a:hover:after,
#wrapper #content_left .op-soft-title a:visited:hover:after,
#wrapper #content_left .result a:visited:hover:after,
#wrapper #content_left .result-op a:visited:hover:after,
#wrapper #content_left > .c-container a:visited:hover:after,
.pf,
.s-top-username,
.selected-search-box,
#searchTag,
.new-pmd .c-gap-top-xsmall,
.AC.sp-separator,
.s_tab,
#result_logo,
.toindex,
.soutu-btn,
.quickdelete-line,
.soutu-hover-tip,
div[class*="pc-source"],
div[class*="source_"],
.op-guide-cont,
.c-showurl,
.c-tools,
.bdsug-feedback-wrap,
.c-gap-top-mini,
div[class*="daoliu"],
.sc-card-footer,
div[class*="fy-star-box"],
div[class*="_bg-header_"],
div[class*="_new-kg-header_"],
div[tpl="app/hit-top-new"],
div[tpl="app/footer"],
div[tpl="app/rs"],
div[tpl="app/search-tool"],
div[class*="fy-dictwisenew-mnemonic"],
div[class*="video-wrap"],
div[class*="exam_"],
/* Hide Baidu Baike results for celebrity rankings */
.c-group-wrapper,
.search-source-wrap,
.ipt_rec,
.quickdelete,
div[class*="blog-more-wrap"],
h3::before,
div[class*="sourcebox_"],
/* AI summary result style optimization */
div[tpl="wenda_index"] div[class*="interact-wrapper"],
/* Baidu Wenku result style optimization */
div[tpl*="wenku_wenshu"] div[class*="footer"],
div[tpl*="wenku_wenshu"] a[class*="check-more"],
div[tpl="ms_mark"] div[class*="link-more_"],
div[tpl="ms_number"] div[class*="link-more_"],
div[class="cu-mt-sm-lg"],
span[class*="detail-btn_"] {
  display: none !important;
}

/* Developer search result box adaptation */
div[tpl*="kaifa_"] {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  & > h3 {
    width: 100%;
    margin: 0;
  }
}

/* Phone number query */
div[tpl="ms_mark"],
div[tpl="ms_number"] {
  & .new-pmd .c-gap-top-xsmall {
    display: block !important;
  }
}

/* Baidu Wenku result style optimization */
div[tpl*="wenku_wenshu"] {
  & div[class*="info-wrap-new"] {
    opacity: 0;
  }
}

/* Special reminder for disease-related questions */
div[tpl="ask_doctor"],
div[tpl="wenda_abstract_pc"],
div[tpl="med_disease_kg_collection_san"] {
  background-image: linear-gradient(to right, #ff758c 0%, #ff7eb3 100%);
  display: -webkit-box !important;
  display: -ms-flexbox !important;
  display: flex !important;
  -webkit-box-align: center !important;
  -ms-flex-align: center !important;
  align-items: center !important;
  padding: 15px !important;
  &::after {
    font-size: 15px;
    font-weight: bold;
    color: #fff;
    content: "Important reminder: You are searching for disease-related questions, please do not easily trust online results, seek medical attention in time" !important;
    display: block !important;
    margin-right: auto !important;
    margin-left: auto !important;
  }
  &::before {
    content: "" !important;
  }
}

/* Result box optimization */
#container {
  margin-left: unset !important;
  width: 100%;
}

/* Baidu Baike optimization */
.cos-row .cos-col {
  width: 15% !important;
}
.cu-border {
  width: 100%;
  padding: 0 0px 0px 20px !important;
}

.cu-border,
div[class*="re-box"],
table {
  box-shadow: none !important;
  width: 100%;
}

.result,
.result-op.c-container.new-pmd {
  border: 2px solid rgba(0, 0, 0, 0.1) !important;
  width: 100%;
  box-shadow: none !important;
  border-radius: 6px !important;
  transition: border 0.15s ease-in-out;
}

#container.sam_newgrid .c-container .t a,
#container.sam_newgrid .c-container .c-title a {
  text-decoration: none !important;
}

#wrapper #content_left .op-soft-title h3[class*="t"],
#wrapper #content_left .result h3[class*="t"],
#wrapper #content_left .result-op h3[class*="t"],
#wrapper #content_left > .c-container h3[class*="t"],
#wrapper #content_left > .c-container h3[class*="t"] {
  background-color: #f8f8f8;
  margin: 0px -8px 10px -20px;
  padding: 8px 20px 5px;
  border-radius: 5px 5px 0 0;
}

#wrapper #rs,
#wrapper #content_left .result,
#wrapper #content_left .result-op,
#wrapper #content_left > .c-container {
  display: flex;
  align-items: center;
  & > div {
    margin: 0 !important;
    width: 100% !important;
  }
  /* Fallback for some results that may not match */
  & > div > div {
    margin: 0 !important;
    width: 100% !important;
  }
}

.result:hover,
.result-op.c-container.new-pmd:hover {
  border: 2px solid rgb(0 186 145 / 60%) !important;
  box-shadow: none !important;
  border-radius: 6px !important;
  transition: border 0.15s ease-in-out;
}

a[class*="foot-more"] {
  margin-top: 8px;
}

#content_left {
  padding-top: 85px;
  width: 100% !important;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-left: unset !important;
  padding-left: unset !important;
}

#form.has-soutu .quickdelete {
  right: 10px !important;
}

.fm.has-soutu {
  display: flex;
  flex-direction: row;
  min-width: 650px;
}

.bdsug.bdsug-new {
  width: 528px !important;
}

/* Navigation bar optimization */
#wrapper #head {
  min-width: unset !important;
}

.s_form_wrapper {
  width: 100%;
  justify-content: center;
}

#form .s_ipt_wr {
  width: 100% !important;
  margin: 0;
  padding: 0;
  background: transparent;
  box-shadow: none;
}

#wrapper #kw {
  outline-width: 0px;
  outline-style: solid;
  color: rgba(107, 114, 128, 1);
  transition: all 0.2s ease-in-out;
  box-shadow: 0 0px 0px 0px rgb(182 182 182 / 20%),
    0 0px 0px 0px rgb(182 182 182 / 20%);
  padding: 5px 10px;
  background-color: rgb(255 255 255 / 1);
  border-color: rgb(209, 213, 219);
  border-width: 1px !important;
  border-radius: 7px;
  border-style: solid;
  margin: 0;
  font-size: 15px;
  line-height: 1;
  width: 100% !important;
  height: 100%;
}

#wrapper #kw:focus {
  box-shadow: 0 10px 15px -3px rgb(182 182 182 / 20%),
    0 4px 6px -4px rgb(182 182 182 / 20%);
  transition: all 0.2s ease-in-out;
}

.wrapper_new.wrapper_s #form .bdsug-new,
.wrapper_new #form .bdsug-new {
  width: fit-content !important;
  border: 2px solid #e6e6e6 !important;
  border-radius: 7px;
  background: rgba(250, 250, 252);
  top: 50px;
  left: 50%;
  transform: translateX(-50%);
  padding: 0;
}

.wrapper_new #form .bdsug-new ul {
  border: none !important;
}

.wrapper_s #u {
  height: 100% !important;
  margin: 0 !important;
  display: flex;
  gap: 20px;
  align-items: center;
  & > #myuser {
    margin: 0 !important;
  }
}

#u #myuser {
  margin: 0 !important;
}

.wrapper_new #u {
  margin: 0 !important;
  padding: 10px 16px 0 0;
  height: 70px !important;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  gap: 20px;
  & #s-top-loginbtn,
  & #user {
    padding: 0 !important;
    background: transparent;
    margin: 0 20px !important;
  }
}

@media screen and (min-width: 1225px) {
  .wrapper_new #u {
    flex-direction: row !important;
  }
}

.c-span12 {
  width: 100%;
}

.c-border {
  box-shadow: none !important;
}

div[tpl="dict3"] {
  padding: 10px 20px !important;
}

body {
  min-width: unset !important;
  & #head {
    background: rgba(248, 248, 248, 0.4) !important;
    border-bottom: none !important;
    backdrop-filter: blur(10px) !important;
  }
}

div[tpl="ai_index"] {
  padding: 10px !important;
}

.wd-ai-index-pc {
  width: 100% !important;
  margin: 0px !important;
}

/* #wrapper #content_left .op-soft-title a,
#wrapper #content_left .result a,
#wrapper #content_left .result-op a,
#wrapper #content_left > .c-container a, */
#container.sam_newgrid .c-container .t a,
#container.sam_newgrid .c-container .c-title a {
  color: #3979d3 !important;
}

/* Additional prompts after Baidu related results */
/* Title alignment optimization */
div[tpl] h3 {
  display: flex;
  align-items: center;
}

div[tpl] h3 > a {
  margin: 0px;
}

/* Music result style optimization */

#container.sam_newgrid td:nth-child(1),
#container.sam_newgrid th:nth-child(1) {
  width: unset !important;
}

/* Prompt section */
div[tpl="sg_kg_entity_san"] h3::after {
  font-size: 12px;
  color: #24bb5b;
  border: 1px solid #24bb5b;
  content: "Encyclopedia";
  margin: 0 5px;
  border-radius: 5px;
  padding: 1px 6px;
  font-weight: normal;
  height: 18px;
  display: flex;
  align-items: center;
}

div[tpl*="fy_"] h3::after {
  font-size: 12px;
  color: #cb3f3f;
  border: 1px solid #cb3f3f;
  content: "Translation";
  margin: 0 5px;
  border-radius: 5px;
  padding: 1px 6px;
  font-weight: normal;
  height: 18px;
  display: flex;
  align-items: center;
}

#b_header {
  border: none !important;
  background-color: transparent !important;
}

#b_content #b_results > li:not(#mfa_root) {
  border: 2px solid rgba(0, 0, 0, 0.1) !important;
  box-shadow: none !important;
  border-radius: 6px !important;
  transition: border 0.15s ease-in-out;
}

#b_content #b_results > li:not(#mfa_root):hover {
  border: 2px solid rgb(0 186 145 / 60%) !important;
  box-shadow: none !important;
  border-radius: 6px !important;
  transition: border 0.15s ease-in-out;
}

#container.sam_newgrid td:nth-child(1),
#container.sam_newgrid th:nth-child(1) {
  width: 0;
}

/* Plugin style input box optimization */
#sp-ac-userstyleTEXT {
  min-width: 100%;
  min-height: 300px;
  margin-left: unset !important;
}

*[ac-needhide] .blockShow:hover {
  border: none;
}

div :has(> .blockShow) {
  padding: 0.1rem 0.2rem !important;

  &::after {
    position: absolute;
    right: 0.2rem;
    content: "Self-intercepting domain name - Click title to show results";
    color: #a9a9a9;
  }
}

.nors {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, 50%);
}

#wrapper #page {
  width: 100% !important;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
}

div[class*="header_"] {
  position: relative;
  display: unset !important;
}

a.c-text {
  position: absolute !important;
  right: 20px !important;
  margin: 0 !important;
  top: 5px !important;
  border-radius: 5px !important;
  padding: 1px 6px !important;
  color: #3476d2 !important;
  background: #fff !important;
  transition: all 0.25s ease-in-out;

  &:hover {
    color: #3476d2 !important;
  }
}
span.c-text {
  margin: 0 !important;
  border-radius: 5px !important;
  padding: 1px 6px !important;
  color: #3476d2 !important;
  background: #fff !important;
  transition: all 0.25s ease-in-out;

  &:hover {
    color: #3476d2 !important;
  }
}

This blacklist-style blocking may miss some promotions, and you can find the corresponding element's tpl attribute to add it yourself.

Of course, if you want a stricter whitelist-style blocking, you can use the one below and add to the whitelist in the same way.

div[tpl] {
    display: none;
}
/* Whitelist */
div[tpl="se_com_default"],/* Normal results */
div[tpl="wenda_abstract_pc"],/* Baidu Zhidao result box */
div[tpl="bk_polysemy"],/* Baidu Baike result box */
div[tpl="img_normal"]/* Baidu image result box */
{
    display: block!important;
}

Here are some comparisons of the search page before and after blocking:

Search keyword: Steam

Search keyword: Cold symptoms

After blocking, the entire search page looks much cleaner, and I no longer have to see those ubiquitous promotions.

This article is synchronized and updated to xLog by Mix Space. The original link is https://www.vinking.top/posts/codes/baidu-ad-filter-custom-css

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.