Greasy Fork镜像 支持简体中文。

B++

Remove the random recommendations, bottom bar, sidebar, microphone, and search optimization from the Bing search page. Remove the website logo and switch to a dual-column search result layout. Automatically redirect to the correct Baidu Tieba page. 移除必应搜索页面莫名其妙的推荐、底部栏、侧边栏、麦克风、优化搜索等,去除网页logo,改成双列搜索结果,百度贴吧自动正确跳转

  1. // ==UserScript==
  2. // @name B++
  3. // @name:zh-CN B艹:必应搜索页面大修
  4. // @name:en B++:Bing Search Page Overhaul
  5. // @namespace Bing Plus Plus
  6. // @version 2.01
  7. // @description:zh-CN 移除必应搜索页面大量元素,去除网页logo,改成双列瀑布流结果,百度贴吧自动正确跳转,自动连续到下一页
  8. // @description:en Remove a large number of elements on the Bing search page, remove the webpage logo, change to a two-column waterfall layout for the results, ensure Baidu Tieba automatically redirects correctly, and automatically continue to the next page.
  9. // @author Yog-Sothoth
  10. // @match https://*.bing.com/search*
  11. // @grant GM_addStyle
  12. // @license MIT
  13. // @description Remove the random recommendations, bottom bar, sidebar, microphone, and search optimization from the Bing search page. Remove the website logo and switch to a dual-column search result layout. Automatically redirect to the correct Baidu Tieba page. 移除必应搜索页面莫名其妙的推荐、底部栏、侧边栏、麦克风、优化搜索等,去除网页logo,改成双列搜索结果,百度贴吧自动正确跳转
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. /**
  20. * 删除指定选择器匹配的所有元素,应该能优化一下
  21. */
  22. function removeElement(selector) {
  23. const elements = document.querySelectorAll(selector);
  24. elements.forEach(element => element.remove());
  25. }
  26.  
  27. /**
  28. * 修正 Bing 搜索结果中贴吧链接的 URL,将 "jump2.bdimg" 或 "jump.bdimg" 替换为 "tieba.baidu",谁把跳转页也放进正常爬虫了,百度的robot.txt写错了?
  29. */
  30. function replace() {
  31. let as = document.querySelectorAll('#b_content .b_algo h2 a');
  32. let as2 = document.querySelectorAll('#b_content .b_algo .b_tpcn .tilk');
  33.  
  34. for (let i = 0; i < as.length; i++) {
  35. let url = as[i].getAttribute('href');
  36. let new_url = url.replace(/jump2\.bdimg|jump\.bdimg/, 'tieba.baidu');
  37. as[i].setAttribute('href', new_url);
  38. as2[i].setAttribute('href', new_url);
  39. }
  40. }
  41.  
  42. /**
  43. * 双页紧凑瀑布流
  44. */
  45. const css = `
  46. #b_context { display: none; } /* 隐藏 Bing 侧边栏 */
  47. #b_content { padding: 30px 15px !important; } /* 调整搜索内容区域的边距 */
  48. #b_results { display: flex; flex-wrap: wrap; width: 100% !important; } /* 结果列表使用流式布局 */
  49. #b_results > li { width: 40%; margin-right: 50px; } /* 调整搜索结果项的宽度和间距 */
  50. .b_pag, .b_ans { width: 100% !important; } /* 分页和答案区域全宽 */
  51. #b_results .ContentItem { display: inline-flex; flex-wrap: wrap; width: 40%; } /* 文章项布局优化 */
  52. #b_results .MainContent_Sub_Left_MainContent { max-width: 100% !important; } /* 主内容区域最大化适应 */
  53. `;
  54. GM_addStyle(css);
  55.  
  56. /**
  57. * 元素选择器
  58. */
  59. const elementsToRemove = [
  60. '.b_ans', '.b_ans .b_mop', '.b_vidAns', '.b_rc_gb_sub', '.b_rc_gb_sub_section',
  61. '.b_rc_gb_scroll', '.b_msg', '.b_canvas', '.b_footer', '.b_phead_sh_link',
  62. '.b_sh_btn-io', '#id_mobile', '[aria-label="更多结果"]', '.b_algoRCAggreFC',
  63. '.b_factrow b_twofr', '[id^="mic_"]', '[class="tpic"]',
  64. '[class="b_vlist2col b_deep"]', '[class="b_deep b_moreLink "]',
  65. '.b_algo b_vtl_deeplinks', '[class="tab-head HeroTab"]',
  66. '[class="tab-menu tab-flex"]', '[class="b_deepdesk"]',
  67. '[class^="b_algo b_algoBorder b_rc_gb_template b_rc_gb_template_bg_"]',
  68. '[class="sc_rf"]', '[class="b_algospacing"]','[id="b_pole"]'
  69. ];
  70.  
  71. /**
  72. * 监听 DOM 变化,每次变化时删除指定的页面元素。
  73. */
  74. const observer = new MutationObserver(() => {
  75. elementsToRemove.forEach(removeElement);
  76. });
  77. observer.observe(document.body, { childList: true, subtree: true });
  78.  
  79. /**
  80. * 清理大多数大的块状结果,这东西只能占用页面
  81. */
  82. function updateClassForBAlgoElements() {
  83. const bContent = document.getElementById('b_results');
  84. if (bContent) {
  85. Array.from(bContent.children).forEach(element => {
  86. if (element.classList.contains('b_algo') && element.classList.contains('b_rc_gb_template')) {
  87. element.classList.remove(...[...element.classList].filter(cls => cls.startsWith('b_rc_gb_template_bg_')));
  88. element.classList.add('b_algo');
  89. }
  90. });
  91. }
  92. }
  93.  
  94. /**
  95. * 简化 Bing 搜索 URL,去除不必要的参数,仅保留查询参数 "q" 和 "first",bing的页面计数靠后者,挺怪的
  96. */
  97. function simplifyBingUrl() {
  98. const urlObj = new URL(window.location.href);
  99. const query = urlObj.searchParams.get('q');
  100. const first = urlObj.searchParams.get('first');
  101. let simplifiedUrl = `${urlObj.origin}${urlObj.pathname}?q=${encodeURIComponent(query)}`;
  102. if (first) simplifiedUrl += `&first=${encodeURIComponent(first)}`;
  103. if (query && window.location.href !== simplifiedUrl) history.replaceState(null, '', simplifiedUrl);
  104. return window.location.href;
  105. }
  106.  
  107. /**
  108. * 自动连续页(搞页面位置标签貌似没什么用,不弄了)
  109. */
  110. function processBingSearchPage() {
  111. const urlParams = new URLSearchParams(window.location.search);
  112. let first = parseInt(urlParams.get('first'), 10) || 1;
  113. const query = urlParams.get('q');
  114. const resultsContainer = document.getElementById('b_results');
  115. const paginationElement = document.querySelector('.b_pag');
  116.  
  117. if (first === 1) fetchResults(5);
  118.  
  119. window.addEventListener('scroll', () => {
  120. if ((window.innerHeight + window.scrollY) >= (document.body.offsetHeight - 300)) {
  121. first += 10;
  122. fetchResults(first);
  123. }
  124. });
  125.  
  126. function fetchResults(pageFirst) {
  127. fetch(`https://www4.bing.com/search?q=${query}&first=${pageFirst}`)
  128. .then(response => response.text())
  129. .then(data => {
  130. const parser = new DOMParser();
  131. const doc = parser.parseFromString(data, 'text/html');
  132. const results = doc.querySelectorAll('.b_algo');
  133. results.forEach(result => {
  134. resultsContainer.insertBefore(result.cloneNode(true), paginationElement);
  135. });
  136. })
  137. .catch(error => console.error('Error fetching results:', error));
  138. }
  139. }
  140.  
  141. /**
  142. * 自动将 Bing 网址的 "www." 或 "cn." 前缀替换为 "www4.",应对白屏bug和可能的加速访问
  143. */
  144. function redirectTowww4IfNeeded() {
  145. const urlObj = new URL(window.location.href);
  146. if (/^(www\.|cn\.)/.test(urlObj.hostname)) {
  147. window.location.href = `https://www4.${urlObj.hostname.replace(/^(www\.|cn\.)/, '')}${urlObj.pathname}${urlObj.search}`;
  148. }
  149. }
  150.  
  151. redirectTowww4IfNeeded();
  152. updateClassForBAlgoElements();
  153. elementsToRemove.forEach(removeElement);
  154. simplifyBingUrl();
  155. replace();
  156. processBingSearchPage();
  157.  
  158. /**
  159. * 监听页面变动以保持替换(以后可能改成局部以提升效率)
  160. */
  161. var _pushState = window.history.pushState;
  162. window.history.pushState = function() {
  163. replace();
  164. console.log('History changed');
  165. return _pushState.apply(this, arguments);
  166. };
  167. })();
  168.  
  169.  

QingJ © 2025

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