Google Tools Button Clicker

Automatically clicks Tools button on Google search.

目前為 2020-01-03 提交的版本,檢視 最新版本

  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.1.1
  11. // @run-at document-start
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. /*
  16. 「全ての言語」などにhoverで開く機能を付与する?
  17. */
  18. (function(){
  19. const TARGETS = {
  20. tools: () => document.querySelector('#hdtb-tls'),
  21. menus: () => document.querySelector('#hdtbMenus'),
  22. };
  23. let openMenus = function(){
  24. let menus = TARGETS.menus(), tools = TARGETS.tools(), ae = document.activeElement;
  25. if(menus && menus.getAttribute('aria-expanded') === 'true') return;
  26. if(tools && tools.classList.contains('hdtb-tl-sel')) return;
  27. if(tools) tools.click(), ae.focus();
  28. };
  29. if(document.hidden) window.addEventListener('focus', openMenus, {once: true});
  30. else window.addEventListener('load', setTimeout.bind(null, openMenus, 250));
  31. })();