Fantia image slideshow keyboard shortcuts

Extending the keyboard shortcuts for the Fantia image slideshow interface

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Fantia image slideshow keyboard shortcuts
// @namespace    http://rjhsiao.me/gmscripts
// @version      1.0.0
// @description  Extending the keyboard shortcuts for the Fantia image slideshow interface
// @author       RJ Hsiao
// @supportURL   https://github.com/RJHsiao/fantia-image-slideshow-keyboard-shortcuts
// @license      gpl
// @match        https://fantia.jp/posts/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=fantia.jp
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Workaround: do not scroll up to page top when esc-key pressed on image slideshow showing
    document.addEventListener('keydown', ev => {
        if (document.getElementById('image-slideshow') && ev.key === 'Escape') {
            ev.preventDefault();
            ev.stopPropagation();
            return;
        }
    });

    document.addEventListener('keyup', ev => {
        if (ev.altKey || ev.ctrlKey || ev.metaKey || ev.shiftKey) {
            return;
        }
        let imgSS = document.getElementById('image-slideshow');
        if (!imgSS) {
            return;
        }
        switch (ev.key) {
            case 'ArrowLeft':
                imgSS.querySelector('a.move-button.prev.clickable')?.click()
                return;
            case 'ArrowRight':
                imgSS.querySelector('a.move-button.next.clickable')?.click()
                return;
            case 'Escape':
                imgSS.querySelector('a.btn.btn-dark.btn-sm > i.fa-close')?.click()
                return;
        }
    });
    console.log("Fantia image slideshow key binging loaded.");
})();