Instagram: Arrow Keys for Multi-Image Posts

Makes right/left keys navigate next/previous images in multi-image posts, as well as to adjacent posts. Holding shift, right/left jumps directly between posts. Esc key closes posts.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Instagram: Arrow Keys for Multi-Image Posts
// @description  Makes right/left keys navigate next/previous images in multi-image posts, as well as to adjacent posts. Holding shift, right/left jumps directly between posts. Esc key closes posts.
// @match        https://www.instagram.com/*
// @version      0.7
// @author       mica
// @namespace    greatest.deepsurf.us/users/12559
// @license      MIT
// ==/UserScript==


const nextImg = () => document.querySelector('article button[aria-label="Next"]');
const prevImg = () => document.querySelector('article button[aria-label="Go back"]');
const nextPgImg = () => document.querySelector('div[role="button"] button[aria-label="Next"]');
const prevPgImg = () => document.querySelector('div[role="button"] button[aria-label="Go back"]');
const nextPost = () => document.querySelector('svg[aria-label="Next"]');
const prevPost = () => document.querySelector('svg[aria-label="Go back"]');
const closePost = () => document.querySelector('svg[aria-label="Close"]');
const openFirst = () => document.querySelector('[role="tablist"]');

document.addEventListener('keydown', event => {
    if (!location.pathname.match(/^\/$|^\/reels\/|^\/direct\/|^\/accounts\/|^\/your_activity\/|^\/.*\/saved\//g)) {
        event.stopPropagation();
        switch (true) {
            case (event.shiftKey && event.key == 'ArrowRight'):
                nextPost().parentElement.click();
                break;
            case (event.key == 'ArrowRight'):
                if (nextImg()) {
                    nextImg().click();
                } else if (nextPost()) {
                    nextPost().parentElement.click();
                } else if (openFirst()) {
                    openFirst().parentNode.nextSibling.querySelector('a').click();
                } else {
                    nextPgImg().click();
                }
                break;
            case (event.shiftKey && event.key == 'ArrowLeft'):
                prevPost().parentElement.click();
                break;
            case (event.key == 'ArrowLeft'):
                if (prevImg()) {
                    prevImg().click();
                } else if (prevPost()) {
                    prevPost().parentElement.click();
                } else {
                    prevPgImg().click();
                }
                break;
            case (event.key == 'Escape'):
                closePost().parentElement.click();
                break;
        }
    }
});