From d03b5a2c824f4a5539186e2fc132e8736ea25c46 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Mon, 14 Sep 2020 21:35:28 -0400 Subject: [PATCH] add shortcut to open full image (furbooru/philomena#32) --- assets/js/shortcuts.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/assets/js/shortcuts.js b/assets/js/shortcuts.js index 4edb6e2c..bfbb0491 100644 --- a/assets/js/shortcuts.js +++ b/assets/js/shortcuts.js @@ -2,13 +2,22 @@ * Keyboard shortcuts */ +import { $ } from './utils/dom'; + function getHover() { - const thumbBoxHover = document.querySelector('.media-box:hover'); + const thumbBoxHover = $('.media-box:hover'); if (thumbBoxHover) return thumbBoxHover.dataset.imageId; } +function openFullView() { + const imageHover = $('[data-uris]:hover'); + if (!imageHover) return; + + window.location = JSON.parse(imageHover.dataset.uris).full; +} + function click(selector) { - const el = document.querySelector(selector); + const el = $(selector); if (el) el.click(); } @@ -25,6 +34,7 @@ const keyCodes = { 82() { click('.js-rand'); }, // R - go to random image 83() { click('.js-source-link'); }, // S - go to image source 76() { click('.js-tag-sauce-toggle'); }, // L - edit tags + 79() { openFullView() }, // O - open original 70() { // F - favourite image getHover() ? click(`a.interaction--fave[data-image-id="${getHover()}"]`) : click('.block__header a.interaction--fave');