GollyJer's Auto-Expand Google Search Tools

Show the Search Tools on Google search results instead of result-count and query-speed.

  1. // ==UserScript==
  2. // @name GollyJer's Auto-Expand Google Search Tools
  3. // @description Show the Search Tools on Google search results instead of result-count and query-speed.
  4. // @namespace gollyjer.com
  5. // @license MIT
  6. // @version 1.4
  7. // @match https://www.google.com/*
  8. // @require https://code.jquery.com/jquery-3.6.0.min.js
  9. // @grant GM_addStyle
  10. // ==/UserScript==
  11.  
  12. /* globals $, waitForKeyElements */
  13.  
  14. // Hide the Search Tools button.
  15. GM_addStyle('#hdtb-tls { display: none !important; }');
  16.  
  17. // Speed up visibility of the Seach Tools menu by removing the animation.
  18. GM_addStyle('#hdtbMenus { transition: none !important; }');
  19.  
  20. // Show the Search Tools menu.
  21. waitForKeyElements('#hdtb-tls', clickUntilItSticks);
  22.  
  23. function clickUntilItSticks(element) {
  24. var searchToolbar = $('#hdtbMenus')[0];
  25. console.log('searchToolbar', searchToolbar);
  26. var sanityCount = 1;
  27. var menusVisiblePoller = setInterval(function () {
  28. if (sanityCount < 20 && searchToolbar.offsetWidth === 0 && searchToolbar.offsetHeight === 0) {
  29. element.click();
  30. } else {
  31. clearInterval(menusVisiblePoller);
  32. }
  33. }, 88);
  34. }
  35.  
  36.  
  37. /*
  38. UNABLE TO INCLUDE SCRIPT WHEN USING GREASYFORK SO DIRECTLY INCLUDING HERE.
  39. Credit to https://github.com/CoeJoder/waitForKeyElements.js
  40. v1.2
  41. */
  42. function waitForKeyElements(selectorOrFunction, callback, waitOnce, interval, maxIntervals) {
  43. if (typeof waitOnce === 'undefined') {
  44. waitOnce = true;
  45. }
  46. if (typeof interval === 'undefined') {
  47. interval = 300;
  48. }
  49. if (typeof maxIntervals === 'undefined') {
  50. maxIntervals = -1;
  51. }
  52. var targetNodes =
  53. typeof selectorOrFunction === 'function'
  54. ? selectorOrFunction()
  55. : document.querySelectorAll(selectorOrFunction);
  56.  
  57. var targetsFound = targetNodes && targetNodes.length > 0;
  58. if (targetsFound) {
  59. targetNodes.forEach(function (targetNode) {
  60. var attrAlreadyFound = 'data-userscript-alreadyFound';
  61. var alreadyFound = targetNode.getAttribute(attrAlreadyFound) || false;
  62. if (!alreadyFound) {
  63. var cancelFound = callback(targetNode);
  64. if (cancelFound) {
  65. targetsFound = false;
  66. } else {
  67. targetNode.setAttribute(attrAlreadyFound, true);
  68. }
  69. }
  70. });
  71. }
  72.  
  73. if (maxIntervals !== 0 && !(targetsFound && waitOnce)) {
  74. maxIntervals -= 1;
  75. setTimeout(function () {
  76. waitForKeyElements(selectorOrFunction, callback, waitOnce, interval, maxIntervals);
  77. }, interval);
  78. }
  79. }