Power User Instagram Keyboard Shortcuts

Adds powerful keyboard shortcuts that should be built-in for power-users.

目前为 2020-02-16 提交的版本。查看 最新版本

// ==UserScript==
// @name         Power User Instagram Keyboard Shortcuts
// @namespace    http://tampermonkey.net/
// @version      1.2.0
// @description  Adds powerful keyboard shortcuts that should be built-in for power-users.
// @author       French Bond
// @match        https://www.instagram.com/*
// @grant        none
// @require      https://code.jquery.com/jquery-3.4.1.min.js
// ==/UserScript==

/* globals jQuery, $ */
/* jshint esversion: 6 */

let seeAll = true;
let currentArticle = null;
let searchFocused = false;
let scrolling = false;

$(function() {
    'use strict';

    const headerHeight = 62;
    const scrollSpeed = 200;

    // Handle search box focus
    $('[placeholder="Search"]')
        .focus(() => { searchFocused = true })
        .blur(() => { searchFocused = false });

    // Handle key press
    $('body').keydown(function(e) {
        if (searchFocused || scrolling) return;

        // A - Toggle see all
        if (e.keyCode === 65) {
            seeAll = !seeAll;
        }

        // K - Scroll down
        if (e.keyCode === 75) {
            if (seeAll && $(currentArticle).find('.coreSpriteRightChevron').length) {
                $(currentArticle).find('.coreSpriteRightChevron').parent().click();
            } else {
                $('article').each(function(index, article) {
                    const top = $(article).offset().top - headerHeight;
                    if (top > $(window).scrollTop() + 1) {
                        scrolling = true;
                        $("html, body").animate(
                            { scrollTop: top },
                            {
                                duration: scrollSpeed,
                                done: () => { scrolling = false; }
                            }
                        );
                        currentArticle = article;
                        return false;
                    }
                });
            }
        }

        // I - Scroll up
        if (e.keyCode === 73) {
            if (seeAll && $(currentArticle).find('.coreSpriteLeftChevron').length) {
                $(currentArticle).find('.coreSpriteLeftChevron').parent().click();
            } else {
                let previousArticle = null;
                $('article').each(function(index, article) {
                    const top = $(article).offset().top - headerHeight;
                    if (top > $(window).scrollTop() - headerHeight - 20) {
                        if (previousArticle) {
                            scrolling = true;
                            $("html, body").animate(
                                { scrollTop: $(previousArticle).offset().top - headerHeight },
                                {
                                    duration: scrollSpeed,
                                    done: () => { scrolling = false; }
                                }
                            );
                            currentArticle = previousArticle;
                        }
                        return false;
                    }
                    previousArticle = article;
                });
            }
        }

        // L - Scroll right
        if (e.keyCode === 76) {
            $(currentArticle).find('.coreSpriteRightChevron').parent().click();
        }

        // J - Scroll left
        if (e.keyCode === 74) {
            $(currentArticle).find('.coreSpriteLeftChevron').parent().click();
        }

        // U - Like
        if (e.keyCode == 85) {
            const actionsDiv = $(currentArticle).children()[2];
            const buttons = $(actionsDiv).find('button');
            $(buttons[0]).click();
        }

        // O - Save
        if (e.keyCode == 79) {
            const actionsDiv = $(currentArticle).children()[2];
            const buttons = $(actionsDiv).find('button');
            $(buttons[3]).click();
        }

        // M - Play/stop
        if (e.keyCode == 77) {
            $(currentArticle).find('[aria-label="Control"]').click();
        }

    });

});

QingJ © 2025

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