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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Instagram: Arrow Key Navigation for Multi-Image Posts
// @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)
// @match        https://www.instagram.com/*
// @version      0.2
// @namespace    greasyfork.org/users/12559
// @license      MIT
// ==/UserScript==

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