Instagram: Arrow Key Navigation for Multi-Image Posts

Make the right/left keys go to the next/previous image in a multi-image post, then on to the adjacent post. While holding shift, right/left will jump directly between posts

目前為 2024-01-18 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Instagram: Arrow Key Navigation for Multi-Image Posts
  3. // @description Make the right/left keys go to the next/previous image in a multi-image post, then on to the adjacent post. While holding shift, right/left will jump directly between posts
  4. // @match https://www.instagram.com/*
  5. // @version 0.3
  6. // @namespace greasyfork.org/users/12559
  7. // @license MIT
  8. // ==/UserScript==
  9.  
  10. let nextBtns;
  11. let backBtns;
  12. document.addEventListener('keydown', (event) => {
  13. event.stopPropagation();
  14. if (event.shiftKey && event.key === 'ArrowRight') {
  15. document.querySelector('svg[aria-label="Next"]').closest('button').click();
  16. } else if (event.key === 'ArrowRight') {
  17. if (document.querySelectorAll('button[aria-label="Next"]').length === 1 && nextBtns === 2) {
  18. document.querySelector('svg[aria-label="Next"]').closest('button').click();
  19. } else if (document.querySelectorAll('button[aria-label="Next"]').length === 1) {
  20. document.querySelector('button[aria-label="Next"]').click();
  21. } else if (document.querySelectorAll('button[aria-label="Next"]').length === 2) {
  22. document.querySelectorAll('button[aria-label="Next"]')[1].click();
  23. nextBtns = 2;
  24. } else {
  25. document.querySelector('svg[aria-label="Next"]').closest('button').click();
  26. }
  27. } else if (event.shiftKey && event.key === 'ArrowLeft') {
  28. document.querySelector('svg[aria-label="Go Back"]').closest('button').click();
  29. } else if (event.key === 'ArrowLeft') {
  30. if (document.querySelectorAll('button[aria-label="Go Back"]').length === 1 && backBtns === 2) {
  31. document.querySelector('svg[aria-label="Go Back"]').closest('button').click();
  32. } else if (document.querySelectorAll('button[aria-label="Go Back"]').length === 1) {
  33. document.querySelector('button[aria-label="Go Back"]').click();
  34. } else if (document.querySelectorAll('button[aria-label="Go Back"]').length === 2) {
  35. document.querySelectorAll('button[aria-label="Go Back"]')[1].click();
  36. backBtns = 2;
  37. } else {
  38. document.querySelector('svg[aria-label="Go Back"]').closest('button').click();
  39. }
  40. }
  41. }, true);