Better Google (Updated)

Don't be evil

  1. // ==UserScript==
  2. // @name Better Google (Updated)
  3. // @namespace google
  4. // @version 0.1.25
  5. // @description Don't be evil
  6. // @author aligo, adambh, tejaslodaya, re11ding, drwonky
  7. // @license MIT
  8. // @supportURL https://github.com/aligo/better-google
  9. // @supportURL https://github.com/drwonky/better-google
  10. // @match https://*.google.com/search?*
  11. // @include /^https?://(?:www|encrypted|ipv[46])\.google\.[^/]+/(?:$|[#?]|search|webhp)/
  12. // @grant none
  13. // @run-at document-start
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. var betterGoogleRow = function(el) {
  20. var byrV5b = el.querySelectorAll('.byrV5b');
  21. var aboutResult = el.querySelectorAll('.csDOgf');
  22. var otherAboutResult = el.querySelectorAll('.eFM0qc');
  23.  
  24. if (byrV5b.length > 0) {
  25. var linkEl = el.querySelector('a');
  26. var addEl = linkEl.nextSibling;
  27.  
  28. var betterAddEl = document.createElement('div');
  29. betterAddEl.className = 'btrAdd';
  30.  
  31. if (addEl) {
  32. for (var i = 0; i < addEl.children.length; i++) {
  33. var _el = addEl.children[i];
  34. if (_el.className.indexOf('byrV5b') == -1) {
  35. betterAddEl.appendChild(_el);
  36. }
  37. }
  38. }
  39.  
  40. var betterEl = document.createElement('div');
  41. betterEl.className = 'btrG';
  42. betterEl.appendChild(betterAddEl);
  43.  
  44. el.appendChild(betterEl);
  45.  
  46. var urlEl = document.createElement('a');
  47. urlEl.href = linkEl.href;
  48. urlEl.target = '_blank';
  49. urlEl.className = 'btrLink';
  50.  
  51. var urlCiteEl = document.createElement('cite');
  52. urlCiteEl.innerText = linkEl.href;
  53. urlCiteEl.className = 'iUh30 bc';
  54. urlEl.appendChild(urlCiteEl);
  55.  
  56. if (otherAboutResult[0]) {
  57. otherAboutResult[0].style = 'text-wrap: nowrap;';
  58. urlEl.appendChild(otherAboutResult[0]);
  59. }
  60.  
  61. var maxWidth = el.clientWidth - betterAddEl.offsetWidth - 10;
  62.  
  63. betterEl.insertBefore(urlEl, betterAddEl);
  64. if (urlEl.offsetWidth > maxWidth) {
  65. urlEl.style.width = maxWidth.toString() + 'px';
  66. }
  67.  
  68. if(aboutResult[0]){
  69. betterEl.appendChild(aboutResult[0]);
  70. }
  71.  
  72. byrV5b.forEach(function(el) { el.remove() });
  73. if (linkEl.querySelector('br:first-child')){
  74. linkEl.querySelector('br:first-child').remove();
  75. }
  76. }
  77. }
  78.  
  79. var prevResultCount = 0;
  80. var bettered = false;
  81.  
  82. var runBetterGoogle = function() {
  83. if (prevResultCount != document.querySelectorAll('.MjjYud .yuRUbf').length) {
  84. document.querySelectorAll('.MjjYud .yuRUbf').forEach(betterGoogleRow);
  85. prevResultCount = document.querySelectorAll('.MjjYud .yuRUbf').length;
  86. }
  87. if ( !bettered ) {
  88. if ( MutationObserver != undefined ) {
  89. var searchEl = document.getElementById('rcnt');
  90. var observer = new MutationObserver(runBetterGoogle);
  91. observer.observe(searchEl, {childList: true, subtree: true});
  92. }
  93. bettered = true;
  94. }
  95. };
  96.  
  97. var prepareStyleSheet = function() {
  98. var style = document.createElement('style');
  99. style.setAttribute('media', 'screen');
  100. style.appendChild(document.createTextNode(''));
  101. document.head.appendChild(style);
  102. style.sheet.insertRule('.btrG { display: flex; word-break: break-all; line-height: 18px; }');
  103. style.sheet.insertRule('.btrG .btrAdd { display: inline-block; vertical-align: top; }');
  104. style.sheet.insertRule('.btrG .btrLink { display: flex; flex-direction: row; vertical-align: top; line-height: 18px; text-decoration: none !important; max-width: 570px;}');
  105. style.sheet.insertRule('.btrG .btrLink cite.iUh30 { color: #006621; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;}');
  106. style.sheet.insertRule('.csDOgf.L48a4c { margin-top: 0px !important; }');
  107. style.sheet.insertRule('.srKDX:has( > .kb0PBd.cvP2Ce.LnCrMe) .btrG .btrLink { max-width: 510px !important;}');
  108. //style.sheet.insertRule('.uhHOwf.ez24Df { display: none !important; }'); //For removing images next to results.
  109. //style.sheet.insertRule('.HGLrXd.NJjxre.iUh30.ojE3Fb:not(.xe8e1b .HGLrXd.NJjxre.iUh30.ojE3Fb) { display: none !important;}');
  110. };
  111.  
  112. var checkElementThenRun = function(selector, func) {
  113. var el = document.querySelector(selector);
  114. if ( el == null ) {
  115. if (window.requestAnimationFrame != undefined) {
  116. window.requestAnimationFrame(function(){ checkElementThenRun(selector, func)});
  117. } else {
  118. document.addEventListener('readystatechange', function(e) {
  119. if (document.readyState == 'complete') {
  120. func();
  121. }
  122. });
  123. }
  124. } else {
  125. func();
  126. }
  127. }
  128. checkElementThenRun('head', prepareStyleSheet);
  129. checkElementThenRun('#rcnt', runBetterGoogle);
  130. })();

QingJ © 2025

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