Auto-Expand Google Search Tools [pure javascript]

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

  1. // ==UserScript==
  2. // @name Auto-Expand Google Search Tools [pure javascript]
  3. // @description Show the Search Tools on Google search results instead of result-count and query-speed.
  4. // @namespace gsAutoExp
  5. // @license MIT
  6. // @version 1.5
  7. // @match https://www.google.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=google.com
  9. // @grant GM_addStyle
  10. // ==/UserScript==
  11.  
  12. /* Inspired by GollyJer's Auto-Expand Google Search Tools v 1.4
  13. https://gf.qytechs.cn/en/scripts/13968-gollyjer-s-auto-expand-google-search-tools */
  14.  
  15. /* globals $, waitForKeyElements */
  16.  
  17. // Hide the Search Tools button.
  18. GM_addStyle('#hdtb-tls { display: none !important; }');
  19.  
  20. // Speed up visibility of the Seach Tools menu by removing the animation.
  21. GM_addStyle('#hdtbMenus { transition: none !important; }');
  22.  
  23. // Show the Search Tools menu.
  24. waitForKeyElements('#hdtb-tls', clickUntilItSticks);
  25.  
  26. function clickUntilItSticks(element) {
  27. var searchToolbar = document.getElementById('hdtbMenus'); // Use getElementById to select the element
  28. console.log('searchToolbar', searchToolbar);
  29. var sanityCount = 1;
  30.  
  31. // Use setInterval to repeatedly check the condition
  32. var menusVisiblePoller = setInterval(function () {
  33. // Check whether the element is still invisible and increment sanityCount
  34. if (sanityCount < 20 && searchToolbar.offsetWidth === 0 && searchToolbar.offsetHeight === 0) {
  35. element.click(); // Trigger the click
  36. sanityCount++; // Increment the sanity counter
  37. } else {
  38. clearInterval(menusVisiblePoller); // Stop polling once the condition is met or the sanity limit is reached
  39. }
  40. }, 88);
  41. }
  42.  
  43. /* Credit to https://github.com/CoeJoder/waitForKeyElements.js v1.3 */
  44.  
  45. function waitForKeyElements(selectorOrFunction, callback, waitOnce, interval, maxIntervals) {
  46. if (typeof waitOnce === "undefined") {
  47. waitOnce = true;
  48. }
  49. if (typeof interval === "undefined") {
  50. interval = 300;
  51. }
  52. if (typeof maxIntervals === "undefined") {
  53. maxIntervals = -1;
  54. }
  55. if (typeof waitForKeyElements.namespace === "undefined") {
  56. waitForKeyElements.namespace = Date.now().toString();
  57. }
  58. var targetNodes = (typeof selectorOrFunction === "function")
  59. ? selectorOrFunction()
  60. : document.querySelectorAll(selectorOrFunction);
  61.  
  62. var targetsFound = targetNodes && targetNodes.length > 0;
  63. if (targetsFound) {
  64. targetNodes.forEach(function(targetNode) {
  65. var attrAlreadyFound = `data-userscript-${waitForKeyElements.namespace}-alreadyFound`;
  66. var alreadyFound = targetNode.getAttribute(attrAlreadyFound) || false;
  67. if (!alreadyFound) {
  68. var cancelFound = callback(targetNode);
  69. if (cancelFound) {
  70. targetsFound = false;
  71. }
  72. else {
  73. targetNode.setAttribute(attrAlreadyFound, true);
  74. }
  75. }
  76. });
  77. }
  78.  
  79. if (maxIntervals !== 0 && !(targetsFound && waitOnce)) {
  80. maxIntervals -= 1;
  81. setTimeout(function() {
  82. waitForKeyElements(selectorOrFunction, callback, waitOnce, interval, maxIntervals);
  83. }, interval);
  84. }
  85. }
  86.  
  87.  

QingJ © 2025

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