Greasy Fork 还支持 简体中文。

Google digits

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

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

  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.2.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.documentElement.appendChild(document.createElement('style')).textContent = /*css*/ `
  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. opacity: .5;
  23. }
  24. `;
  25.  
  26. window.addEventListener('keydown', function(e) {
  27. const k = e.which;
  28. const digit =
  29. k >= 48 && k <= 57 ? k - 48 :
  30. k >= 96 && k <= 105 ? k - 96 :
  31. -1;
  32. if (digit >= 0 &&
  33. location.href.match(/[#&?]q=/) &&
  34. !e.metaKey && !e.ctrlKey &&
  35. e.target.localName != 'input') {
  36. const el = document.querySelectorAll('a h3')[digit - 1];
  37. const link = el && el.closest('a');
  38. if (!link) return;
  39. el.style.backgroundColor = 'yellow';
  40. link.focus();
  41. link.dispatchEvent(new MouseEvent('click',
  42. e.shiftKey && {shiftKey: true} ||
  43. e.altKey && {ctrlKey: true} ||
  44. {}));
  45. setTimeout(() => (el.style.backgroundColor = ''), 100);
  46. }
  47. }, true);