Better Google

Restore google search results to older style with green link below title instead of link above title. Just tweaks the CSS and does some dynamic JS reordering of the DIVs.

  1. // ==UserScript==
  2. // @name Better Google
  3. // @namespace google
  4. // @version 0.1.16.10
  5. // @description Restore google search results to older style with green link below title instead of link above title. Just tweaks the CSS and does some dynamic JS reordering of the DIVs.
  6. // @author aligo, adambh, tejaslodaya, drwonky, yut23
  7. // @license MIT
  8. // @homepageURL https://github.com/aligo/better-google
  9. // @match https://*.google.com/search?*
  10. // @include /^https?://(?:www|encrypted|ipv[46])\.google\.[^/]+/(?:$|[#?]|search|webhp)/
  11. // @grant none
  12. // @run-at document-start
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. var betterGoogleRow = function(el) {
  19. var tbwUpd = el.querySelectorAll('.TbwUpd, .HGLrXd');
  20. if (tbwUpd.length > 0) {
  21. /* Google does A/B testing on the search results page, so the
  22. * structure of the page is not always the same. This code
  23. * tries to find the link element in a few different ways.
  24. * If it can't find it, it just gives up and doesn't do
  25. * anything.
  26. */
  27. var selectors = [
  28. '.yuRUbf > a',
  29. '.yuRUbf > div > a',
  30. '.yuRUbf > div > span > a',
  31. ];
  32. for (const selector of selectors) {
  33. var linkEl = el.querySelector(selector);
  34. if (linkEl) {
  35. break;
  36. }
  37. }
  38. var addEl = linkEl.nextSibling;
  39. if (!addEl) {
  40. // try the parent's sibling, for the span case
  41. addEl = linkEl.parentElement.nextSibling;
  42. }
  43. if (!addEl) {
  44. // entry isn't fully loaded yet
  45. return;
  46. }
  47.  
  48. var betterAddEl = document.createElement('div');
  49. betterAddEl.className = 'btrAdd';
  50.  
  51. // this loop moves the "More options" button into betterAddEl
  52. for (var i = 0; i < addEl.children.length; i++) {
  53. var _el = addEl.children[i];
  54. if (_el.className.includes('TbwUpd') || _el.className.includes('HGLrXd')) {
  55. continue;
  56. }
  57. betterAddEl.appendChild(_el);
  58. }
  59.  
  60. var betterEl = document.createElement('div');
  61. betterEl.className = 'btrG';
  62. betterEl.appendChild(betterAddEl);
  63.  
  64. el.appendChild(betterEl);
  65.  
  66. var urlEl = document.createElement('a');
  67. urlEl.href = linkEl.href;
  68. urlEl.target = '_blank';
  69. urlEl.className = 'btrLink';
  70.  
  71. var urlCiteEl = document.createElement('cite');
  72. urlCiteEl.innerText = linkEl.href;
  73. urlCiteEl.className = 'iUh30 bc';
  74. urlEl.appendChild(urlCiteEl);
  75.  
  76.  
  77. var maxWidth = el.clientWidth - betterAddEl.offsetWidth - 10;
  78.  
  79. betterEl.insertBefore(urlEl, betterAddEl);
  80. if (urlEl.offsetWidth > maxWidth) {
  81. urlEl.style.width = maxWidth.toString() + 'px';
  82. }
  83.  
  84. var aboutResult = el.querySelectorAll('.csDOgf');
  85. if (aboutResult.length > 0) {
  86. betterEl.appendChild(aboutResult[0]);
  87. }
  88. tbwUpd.forEach(function(el) { el.remove() });
  89.  
  90. var brEl = linkEl.querySelector('br:first-child');
  91. if (brEl) {
  92. brEl.remove();
  93. }
  94. }
  95. }
  96.  
  97. var prevResultCount = 0;
  98. var bettered = false;
  99.  
  100. var runBetterGoogle = function() {
  101. if (prevResultCount != document.querySelectorAll('.MjjYud .yuRUbf').length) {
  102. document.querySelectorAll('.MjjYud .yuRUbf').forEach(betterGoogleRow);
  103. prevResultCount = document.querySelectorAll('.MjjYud .yuRUbf').length;
  104. }
  105. if ( !bettered ) {
  106. if ( MutationObserver != undefined ) {
  107. var searchEl = document.getElementById('rcnt');
  108. var observer = new MutationObserver(runBetterGoogle);
  109. observer.observe(searchEl, {childList: true, subtree: true});
  110. }
  111. bettered = true;
  112. }
  113. };
  114.  
  115. var prepareStyleSheet = function() {
  116. // if dark mode is enabled (either manually or by device default),
  117. // Google adds a meta tag to the document which we can check
  118. var link_color = '#006621';
  119. var meta_color_scheme = document.querySelector('meta[name="color-scheme"]');
  120. if (meta_color_scheme != undefined && meta_color_scheme.content.includes('dark')) {
  121. // use a lighter green in dark mode
  122. link_color = '#40965b';
  123. }
  124. var style = document.createElement('style');
  125. style.setAttribute('media', 'screen');
  126. style.appendChild(document.createTextNode(''));
  127. document.head.appendChild(style);
  128. style.sheet.insertRule(`:root { --btrG-link-color: ${link_color}; }`);
  129. style.sheet.insertRule('.btrG { word-break: normal; line-height: 18px; }');
  130. style.sheet.insertRule('.btrG .btrAdd { display: inline-block; vertical-align: top; line-height: 0; }');
  131. style.sheet.insertRule('.btrG .btrLink { display: inline-block; vertical-align: top; line-height: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: none !important; color: var(--btrG-link-color); }');
  132. style.sheet.insertRule('.btrG .btrLink cite.iUh30 { color: var(--btrG-link-color); font-size: 16px; }');
  133. // remove extra space used for new multiline link info card
  134. style.sheet.insertRule('.yuRUbf h3.DKV0Md { margin-top: 0px; }');
  135. };
  136.  
  137. var checkElementThenRun = function(selector, func) {
  138. var el = document.querySelector(selector);
  139. if ( el == null ) {
  140. if (window.requestAnimationFrame != undefined) {
  141. window.requestAnimationFrame(function(){ checkElementThenRun(selector, func)});
  142. } else {
  143. document.addEventListener('readystatechange', function(e) {
  144. if (document.readyState == 'complete') {
  145. func();
  146. }
  147. });
  148. }
  149. } else {
  150. func();
  151. }
  152. }
  153.  
  154. checkElementThenRun('head', prepareStyleSheet);
  155. checkElementThenRun('#rcnt', runBetterGoogle);
  156. })();

QingJ © 2025

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