Google Tools Button Clicker

Automatically clicks Tools button on Google search.

当前为 2020-01-02 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Google Tools Button Clicker
  3. // @name:ja Google Tools Button Clicker
  4. // @namespace knoa.jp
  5. // @description Automatically clicks Tools button on Google search.
  6. // @description:ja Google検索結果のページでツールボタンを自動的にクリックします。
  7. // @include https://www.google.*/search*
  8. // @version 2.1
  9. // @run-at document-start
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. /*
  14. 「全ての言語」などにhoverで開く機能を付与する?
  15. */
  16. (function(){
  17. const TARGETS = {
  18. tools: () => document.querySelector('#hdtb-tls'),
  19. menus: () => document.querySelector('#hdtbMenus'),
  20. };
  21. let openMenus = function(){
  22. let menus = TARGETS.menus(), tools = TARGETS.tools(), ae = document.activeElement;
  23. if(menus && menus.getAttribute('aria-expanded') === 'true') return;
  24. if(tools && tools.classList.contains('hdtb-tl-sel')) return;
  25. if(tools) tools.click(), ae.focus();
  26. };
  27. if(document.hidden) window.addEventListener('focus', openMenus, {once: true});
  28. else window.addEventListener('load', setTimeout.bind(null, openMenus, 250));
  29. })();