Google digits

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

当前为 2016-09-12 提交的版本,查看 最新版本

  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
  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. {
  19. var links = document.querySelectorAll('h3.r a');
  20. var link = links[digit - 1];
  21. if (link) {
  22. link.style.backgroundColor = 'yellow';
  23. location.href = link.href;
  24. e.preventDefault();
  25. e.stopPropagation();
  26. e.stopImmediatePropagation();
  27. }
  28. }
  29. }, true);