Google digits

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

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

  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.1.1
  6. // @author wOxxOm
  7. // @namespace wOxxOm.scripts
  8. // @license MIT License
  9. // @run-at document-start
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (document.head || document.documentElement).appendChild(document.createElement('style')).textContent = '\
  14. body {\
  15. counter-reset: digitnav;\
  16. }\
  17. #rso > div > :not([data-ved]) a h3::before {\
  18. counter-increment: digitnav;\
  19. content: counter(digitnav);\
  20. position: absolute;\
  21. margin-left: -1em;\
  22. }';
  23.  
  24. window.addEventListener('keydown', function(e) {
  25. var digit = e.keyCode - 48;
  26. if (digit >= 1 && digit <= 9 &&
  27. location.href.match(/[#&?]q=/) &&
  28. !e.altKey && !e.ctrlKey && !e.shiftKey && !e.metaKey &&
  29. e.target.localName != 'input') {
  30. var el = document.querySelectorAll('a h3')[digit - 1];
  31. var link = el && el.closest('a');
  32. if (link) {
  33. el.style.backgroundColor = 'yellow';
  34. location.href = link.href;
  35. e.preventDefault();
  36. e.stopPropagation();
  37. e.stopImmediatePropagation();
  38. }
  39. }
  40. }, true);