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 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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);