From fbf4b145a5c95f149949070f84dfe953924ceb29 Mon Sep 17 00:00:00 2001 From: tophf Date: Thu, 16 May 2024 13:54:49 +0300 Subject: [PATCH] 1.3.0 "c" toggles caption, "f" exits fullscreen --- script.user.js | 36 ++++++++++++++++++++++++++---------- types/types.d.ts | 2 ++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/script.user.js b/script.user.js index df836ba..ad8b2e0 100644 --- a/script.user.js +++ b/script.user.js @@ -25,7 +25,7 @@ // @grant GM.setValue // @grant GM.xmlHttpRequest // -// @version 1.2.50 +// @version 1.3.0 // @author tophf // // @original-version 2017.9.29 @@ -410,20 +410,25 @@ const Bar = { } const force = !b && 0; if (!b) b = ai.bar = $new('div', {id: `${PREFIX}bar`, className: `${PREFIX}${className}`}); + ai.barText = label; App.updateStyles(); Bar.updateDetails(); + Bar.setText(cfg.uiInfoCaption ? label : ''); setTimeout(Bar.show, 0, force); - if (/<([a-z][-a-z]*)[^<>]*>[^<>]*<\/\1\s*>/i.test(label)) { // checking for ... - b.innerHTML = trustedHTML ? trustedHTML(label) : label; - } else { - b.textContent = label; - } if (!b.parentNode) { doc.body.appendChild(b); Util.forceLayout(b); } }, + setText(text) { + if (/<([a-z][-a-z]*)[^<>]*>[^<>]*<\/\1\s*>/i.test(text)) { // checking for ... + ai.bar.innerHTML = trustedHTML ? trustedHTML(text) : text; + } else { + ai.bar.textContent = text; + } + }, + show(force) { const b = ai.bar; if (!force && (!cfg.uiInfo || force !== 0 && cfg.uiInfoOnce) || Util.elShown(b)) @@ -723,6 +728,7 @@ Config.DEFAULTS = /** @type mpiv.Config */ { uiFadein: true, uiFadeinGallery: true, // some computers show white background while loading so fading hides it uiInfo: true, + uiInfoCaption: true, uiInfoHide: 3, uiInfoOnce: true, uiShadowColor: '#000000', @@ -957,11 +963,16 @@ const Events = { case 'KeyK': Gallery.next(-1); break; + case 'KeyC': + Bar.setText(ai.bar.firstChild ? '' : ai.barText); + Bar.show(0); + break; case 'KeyD': Req.saveFile(); break; case 'KeyF': - p.requestFullscreen(); + if (p !== document.fullscreenElement) p.requestFullscreen(); + else document.exitFullscreen(); break; case 'KeyH': // flip horizontally case 'KeyV': // flip vertically @@ -3679,6 +3690,7 @@ function createSetupElement() { ].map($newTR)), $new('table', [ ['Antialiasing', '{a}'], + ['Caption in info', '{c}'], ['Download', '{d}'], ['Fullscreen', '{f}'], ['Info', '{i}'], @@ -3753,11 +3765,12 @@ function createSetupElement() { $newCheck('Wait for complete image*', 'waitLoad', '...or immediately show a partial image while still loading'), $new({style: 'display:flex; align-items:center'}, [ - $newCheck('Show info for', 'uiInfo', 'Hotkey: "i" (or hold "Shift") in the popup'), + $newCheck('Info: show for', 'uiInfo', 'Hotkey: "i" (or hold "Shift") in the popup'), $new('input#uiInfoHide', {min: 1, step: 'any', type: 'number'}), 'sec', ]), - $newCheck('Show info only at start*', 'uiInfoOnce', '...or every time the info changes'), + $newCheck('Info: only once*', 'uiInfoOnce', '...or every time the info changes'), + $newCheck('Info: caption*', 'uiInfoCaption', 'Hotkey: "c" in the popup'), $newCheck('Fade-in transition', 'uiFadein'), $newCheck('Fade-in transition in gallery', 'uiFadeinGallery'), ]), @@ -3877,10 +3890,13 @@ function createGlobalStyle() { #\mpiv-bar.\mpiv-show { opacity: 1; } -#\mpiv-bar[data-zoom]::after { +#\mpiv-bar[data-zoom]:not(:empty)::after { content: " (" attr(data-zoom) ")"; opacity: .8; } +#\mpiv-bar[data-zoom]:empty::after { + content: attr(data-zoom); +} #\mpiv-popup.\mpiv-show { display: inline; } diff --git a/types/types.d.ts b/types/types.d.ts index 9eff4fa..38cf006 100644 --- a/types/types.d.ts +++ b/types/types.d.ts @@ -32,6 +32,7 @@ declare namespace mpiv { uiFadein: boolean uiFadeinGallery: boolean uiInfo: boolean + uiInfoCaption: boolean /** seconds */ uiInfoHide: number uiInfoOnce: boolean @@ -113,6 +114,7 @@ declare namespace mpiv { type PopupInfo = { bar: Element + barText: string blobUrl: string /** buffering bar shown */ bufBar: boolean