InoReader follow inner links

Allows to open links that are presented in the article. Press `:` (`;`) to select a link, then press `'` (`"`) to open it in a new tab. Press `/` (`?`) to open in a new background tab.

当前为 2024-03-20 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name InoReader follow inner links
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.0.2
  5. // @description Allows to open links that are presented in the article. Press `:` (`;`) to select a link, then press `'` (`"`) to open it in a new tab. Press `/` (`?`) to open in a new background tab.
  6. // @author Kenya-West
  7. // @require https://unpkg.com/hotkeys-js@3.13.7/dist/hotkeys.js
  8. // @match https://*.inoreader.com/feed*
  9. // @match https://*.inoreader.com/article*
  10. // @match https://*.inoreader.com/folder*
  11. // @icon https://inoreader.com/favicon.ico?v=8
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. (function () {
  16. "use strict";
  17.  
  18. document.head.insertAdjacentHTML("beforeend", `<style>a:focus { outline: 2px solid white; }</style>`);
  19.  
  20. let firstStart = true;
  21. let currentLinkIndex = 0;
  22. let links = []
  23.  
  24. hotkeys('\:,\;', function (event, handler){
  25. event.preventDefault();
  26. if (links.length === 0 && currentLinkIndex === 0) {
  27. currentLinkIndex = -1; // because on first start we need to start from 0
  28. }
  29.  
  30. links = getLinks();
  31. firstStart = false;
  32. if (links.length) {
  33. currentLinkIndex = (currentLinkIndex + 1) % links.length;
  34. links[currentLinkIndex]?.focus();
  35. }
  36. });
  37.  
  38. hotkeys('\',\"', function (event, handler){
  39. // all the same as in previous code block but in reverse order
  40. event.preventDefault();
  41. links = getLinks();
  42. if (links.length) {
  43. currentLinkIndex = (currentLinkIndex - 1 + links.length) % links.length;
  44. links[currentLinkIndex]?.focus();
  45. }
  46. });
  47.  
  48. hotkeys('\],\},\{,\[', function (event, handler){
  49. if (links. Length) {
  50. links[currentLinkIndex]?.click();
  51. }
  52. });
  53.  
  54. function getLinks() {
  55. const links = document.querySelectorAll('.article_content a');
  56. return links;
  57. }
  58.  
  59. })();