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