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    gf.qytechs.cn/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);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址