必应搜索Bing精简加样式优化加去广告

只有3kb,必应搜索Bing精简加样式优化加去广告。

  1. // ==UserScript==
  2. // @name 必应搜索Bing精简加样式优化加去广告
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.7
  5. // @description 只有3kb,必应搜索Bing精简加样式优化加去广告。
  6. // @author 极简实用
  7. // @match https://cn.bing.com/search?*
  8. // @grant none
  9. // @license AGPL
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // 修改 h2 标签字体大小
  16. const h2Elements = document.querySelectorAll('h2');
  17. for (const h2 of h2Elements) {
  18. h2.style.fontSize = '18px'; // 设置字体大小为18px
  19. }
  20.  
  21. // 删除所有 class 为 b_ad 的 li 元素
  22. const adElements = document.querySelectorAll('li.b_ad');
  23. for (const li of adElements) {
  24. li.remove();
  25. }
  26.  
  27. // 删除 class 为 b_rs 的 div 元素
  28. const rsElements = document.querySelectorAll('div.b_rs');
  29. rsElements.forEach(div => div.remove());
  30.  
  31. // 删除 id 为 df_listaa 的 div 元素
  32. const dfListaaElement = document.getElementById('df_listaa');
  33. if (dfListaaElement) {
  34. dfListaaElement.remove();
  35. }
  36.  
  37. // 删除 class 为 b_msg 的 li 元素
  38. const msgElements = document.querySelectorAll('li.b_msg');
  39. msgElements.forEach(li => li.remove());
  40.  
  41. // 删除不必要的 div 元素
  42. const divIDsToRemove = ['b_pole', 'b_tween', 'est_switch', 'id_h', 'b_footer'];
  43. divIDsToRemove.forEach(id => {
  44. const div = document.getElementById(id);
  45. if (div) {
  46. div.remove();
  47. }
  48. });
  49.  
  50. // 删除所有 class 为 b_tpcn 的 div
  51. const b_tpcnElements = document.querySelectorAll('div.b_tpcn');
  52. b_tpcnElements.forEach(div => {
  53. const tpttElement = div.querySelector('div.tptt');
  54. if (tpttElement) {
  55. const tpttText = tpttElement.textContent.trim(); // 获取tptt的文本内容
  56.  
  57. // 找到对应的 h2 标签并检查内容
  58. const h2 = div.closest('li.b_algo').querySelector('h2 a');
  59. if (h2) {
  60. // 检查 a 标签内容中是否已有 tptt 的内容
  61. if (!h2.innerHTML.includes(tpttText)) { // 使用 innerHTML 检查
  62. h2.innerHTML += ' ' + tpttText; // 使用 innerHTML 添加内容
  63. }
  64. }
  65. }
  66. div.remove(); // 删除 b_tpcn 元素
  67. });
  68.  
  69. // 删除所有包含 data-partnertag 的 ul 元素
  70. const partnerTagElements = document.querySelectorAll('ul[data-partnertag]');
  71. partnerTagElements.forEach(ul => ul.remove());
  72.  
  73. // 删除所有包含 p class="b_lineclamp2 b_algoSlug" 的 li class="b_algo" 的元素
  74. const algoElements = document.querySelectorAll('li.b_algo');
  75. algoElements.forEach(li => {
  76. const pElement = li.querySelector('p.b_lineclamp2.b_algoSlug');
  77. if (pElement) {
  78. li.remove();
  79. }
  80. });
  81.  
  82. // 添加自定义样式以隐藏水平滚动条
  83. const style = document.createElement('style');
  84. style.textContent = `
  85. #b_results > .b_algo {
  86. padding: 0px; /* 设置 .b_algo 的 padding 为 0 */
  87. }
  88. #b_content {
  89. padding-top: 0px !important; /* 设置 b_content 的顶部内边距为 0 */
  90. padding-bottom: 0px !important; /* 设置 b_content 的底部内边距为 0 */
  91. }
  92. body, html {
  93. overflow-x: hidden; /* 隐藏水平滚动条 */
  94. }
  95. `;
  96. document.head.appendChild(style);
  97. })();