Instagram: Arrow Key Navigation for Multi-Image Posts

Right/left keys will go to the next/previous image within a multi-image post, as well as between posts. While holding the shift key, right/left only jumps between posts (the current default behavior)

当前为 2024-01-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Instagram: Arrow Key Navigation for Multi-Image Posts
  3. // @description Right/left keys will go to the next/previous image within a multi-image post, as well as between posts. While holding the shift key, right/left only jumps between posts (the current default behavior)
  4. // @match https://www.instagram.com/*
  5. // @version 0.2
  6. // @namespace greasyfork.org/users/12559
  7. // @license MIT
  8. // ==/UserScript==
  9.  
  10. document.addEventListener('keydown', (event) => {
  11. event.stopPropagation();
  12. if (event.shiftKey && event.key === 'ArrowRight') {
  13. document.querySelector('svg[aria-label="Next"]').closest('button').click();
  14. } else if (event.key === 'ArrowRight') {
  15. if (document.querySelector('button[aria-label="Next"]')) {
  16. document.querySelector('button[aria-label="Next"]').click();
  17. } else {
  18. document.querySelector('svg[aria-label="Next"]').closest('button').click();
  19. }
  20. } else if (event.shiftKey && event.key === 'ArrowLeft') {
  21. document.querySelector('svg[aria-label="Go Back"]').closest('button').click();
  22. } else if (event.key === 'ArrowLeft') {
  23. if (document.querySelector('button[aria-label="Go Back"]')) {
  24. document.querySelector('button[aria-label="Go Back"]').click();
  25. } else {
  26. document.querySelector('svg[aria-label="Go Back"]').closest('button').click();
  27. }
  28. }
  29. }, true);