Fantia image slideshow keyboard shortcuts

Extending the keyboard shortcuts for the Fantia image slideshow interface

当前为 2024-11-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Fantia image slideshow keyboard shortcuts
  3. // @namespace http://rjhsiao.me/gmscripts
  4. // @version 1.0.0
  5. // @description Extending the keyboard shortcuts for the Fantia image slideshow interface
  6. // @author RJ Hsiao
  7. // @supportURL https://github.com/RJHsiao/fantia-image-slideshow-keyboard-shortcuts
  8. // @license gpl
  9. // @match https://fantia.jp/posts/*
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=fantia.jp
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Workaround: do not scroll up to page top when esc-key pressed on image slideshow showing
  18. document.addEventListener('keydown', ev => {
  19. if (document.getElementById('image-slideshow') && ev.key === 'Escape') {
  20. ev.preventDefault();
  21. ev.stopPropagation();
  22. return;
  23. }
  24. });
  25.  
  26. document.addEventListener('keyup', ev => {
  27. if (ev.altKey || ev.ctrlKey || ev.metaKey || ev.shiftKey) {
  28. return;
  29. }
  30. let imgSS = document.getElementById('image-slideshow');
  31. if (!imgSS) {
  32. return;
  33. }
  34. switch (ev.key) {
  35. case 'ArrowLeft':
  36. imgSS.querySelector('a.move-button.prev.clickable')?.click()
  37. return;
  38. case 'ArrowRight':
  39. imgSS.querySelector('a.move-button.next.clickable')?.click()
  40. return;
  41. case 'Escape':
  42. imgSS.querySelector('a.btn.btn-dark.btn-sm > i.fa-close')?.click()
  43. return;
  44. }
  45. });
  46. console.log("Fantia image slideshow key binging loaded.");
  47. })();