Google digits

Press 1-9 on Google search page to open the corresponding link

目前為 2020-02-04 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Google digits
  3. // @description Press 1-9 on Google search page to open the corresponding link
  4. // @include https://www.google.tld/*
  5. // @version 1.0.1
  6. // @author wOxxOm
  7. // @namespace wOxxOm.scripts
  8. // @license MIT License
  9. // @run-at document-start
  10. // ==/UserScript==
  11.  
  12. window.addEventListener('keydown', function(e) {
  13. var digit = e.keyCode - 48;
  14. if (digit >= 1 && digit <= 9 &&
  15. location.href.match(/[#&?]q=/) &&
  16. !e.altKey && !e.ctrlKey && !e.shiftKey && !e.metaKey &&
  17. e.target.localName != 'input') {
  18. var el = document.querySelectorAll('a h3')[digit - 1];
  19. var link = el && el.closest('a');
  20. if (link) {
  21. el.style.backgroundColor = 'yellow';
  22. location.href = link.href;
  23. e.preventDefault();
  24. e.stopPropagation();
  25. e.stopImmediatePropagation();
  26. }
  27. }
  28. }, true);