Add Esc key on Google Maps

Add Esc key on Google Maps for better UX.

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

  1. // ==UserScript==
  2. // @name Add Esc key on Google Maps
  3. // @namespace https://github.com/gslin/add-esc-key-on-google-maps
  4. // @match https://www.google.com/maps*
  5. // @grant none
  6. // @version 0.20210101.2
  7. // @author Gea-Suan Lin <gslin@gslin.org>
  8. // @description Add Esc key on Google Maps for better UX.
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (() => {
  13. 'use strict';
  14.  
  15. window.addEventListener('keydown', ev => {
  16. // Esc key
  17. if (27 === ev.keyCode) {
  18. // User page (works only in traditional chinese environment).
  19. let el = document.querySelector('button[aria-label="關閉"]');
  20. if (el && el.offsetHeight > 0 && el.offsetWidth > 0) {
  21. el.click();
  22. return;
  23. }
  24.  
  25. // Comment page (works only in traditional chinese environment).
  26. el = document.querySelector('button[aria-label="返回"]');
  27. if (el && el.offsetHeight > 0 && el.offsetWidth > 0) {
  28. el.click();
  29. return;
  30. }
  31.  
  32. // Store page.
  33. el = document.querySelector('a[guidedhelpid="clear_search"]');
  34. if (el && el.offsetHeight > 0 && el.offsetWidth > 0) {
  35. el.click();
  36. return;
  37. }
  38. }
  39. }, true);
  40. })();