Instagram: Arrow key navigation for multi-image posts too!

Right/left keys will take you to the next/previous image, whether an individual post or multi-image. Why isn't this how the damn website works in the first place!?

2024/01/17のページです。最新版はこちら。

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
// ==UserScript==
// @name         Instagram: Arrow key navigation for multi-image posts too!
// @description  Right/left keys will take you to the next/previous image, whether an individual post or multi-image. Why isn't this how the damn website works in the first place!?
// @match        https://www.instagram.com/*
// @version      0.1
// @namespace    greasyfork.org/users/12559
// @license      MIT
// ==/UserScript==

document.addEventListener('keydown', (event) => {
  event.stopPropagation();
  if (event.key === 'ArrowRight') {
    let nextImg = document.querySelector('button[aria-label="Next"]');
    let nextPost = document.querySelector('svg[aria-label="Next"]').closest('button')
    if (nextImg) {
      nextImg.click();
    } else {
      nextPost.click();
    }
  } else if (event.key === 'ArrowLeft') {
    let prevImg = document.querySelector('button[aria-label="Go Back"]');
    let prevPost = document.querySelector('svg[aria-label="Go Back"]').closest('button')
    if (prevImg) {
      prevImg.click();
    } else {
      prevPost.click();
    }
  }
}, true);