Google Tools Button Clicker

在Google搜索结果的页面上自动单击工具按钮。

当前为 2020-06-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Google Tools Button Clicker
  3. // @name:ja Google Tools Button Clicker
  4. // @name:zh-CN Google Tools Button Clicker
  5. // @description Automatically clicks Tools button on Google search.
  6. // @description:ja Google検索結果のページでツールボタンを自動的にクリックします。
  7. // @description:zh-CN 在Google搜索结果的页面上自动单击工具按钮。
  8. // @namespace knoa.jp
  9. // @include https://www.google.*/search*
  10. // @version 2.2.1
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. /*
  15. [update]
  16. Stability fix.
  17. */
  18. (function(){
  19. const TARGETS = {
  20. tools: () => document.querySelector('#hdtb-tls'),
  21. };
  22. const TIMEOUT = 250;
  23. const openMenus = function(){
  24. if(document.hidden) window.addEventListener('focus', openMenus, {once: true});
  25. let tools = TARGETS.tools(), ae = document.activeElement;
  26. /* not yet ready? */
  27. if(!tools) return setTimeout(openMenus, TIMEOUT);
  28. /* already opened? */
  29. if(tools.getAttribute('aria-expanded') === 'true') return;
  30. /* now being closed, so */
  31. tools.click(), ae.focus();
  32. tools.addEventListener('mouseover', tools.click);
  33. tools.addEventListener('mouseout', tools.click);
  34. tools.addEventListener('click', function(e){
  35. if(e.isTrusted === false) return;
  36. tools.removeEventListener('mouseover', tools.click);
  37. tools.removeEventListener('mouseout', tools.click);
  38. });
  39. };
  40. window.addEventListener('load', openMenus, {once: true});
  41. })();