fix: opacity interaction with the new form guard

This commit is contained in:
arabcoders 2026-04-15 18:14:36 +03:00
parent 9337e81f62
commit e7fd60010b
4 changed files with 51 additions and 27 deletions

View file

@ -4,7 +4,7 @@
:side="direction" :side="direction"
:dismissible="true" :dismissible="true"
:overlay="true" :overlay="true"
:ui="{ content: 'w-full sm:max-w-xl' }" :ui="{ content: 'yt-settings-panel w-full sm:max-w-xl' }"
@update:open="(open) => !open && emitter('close')" @update:open="(open) => !open && emitter('close')"
> >
<template #header> <template #header>

View file

@ -923,11 +923,12 @@ onMounted(async () => {
watch(bg_enable, async (v) => await handleImage(v)); watch(bg_enable, async (v) => await handleImage(v));
watch(simpleMode, () => syncShellModeClass()); watch(simpleMode, () => syncShellModeClass());
watch(bg_opacity, (v) => { watch(bg_opacity, () => {
if (false === bg_enable.value) { if (false === bg_enable.value) {
return; return;
} }
document.querySelector('body')?.setAttribute('style', `opacity: ${v}`);
syncOpacity();
}); });
watch(loadedImage, () => { watch(loadedImage, () => {
@ -936,7 +937,6 @@ watch(loadedImage, () => {
} }
const html = document.documentElement; const html = document.documentElement;
const body = document.querySelector('body');
const style = { const style = {
'background-color': 'unset', 'background-color': 'unset',
@ -954,7 +954,7 @@ watch(loadedImage, () => {
.trim(), .trim(),
); );
html.classList.add('bg-fanart'); html.classList.add('bg-fanart');
body?.setAttribute('style', `opacity: ${bg_opacity.value}`); syncOpacity();
}); });
const handleImage = async (enabled: boolean) => { const handleImage = async (enabled: boolean) => {

View file

@ -1,6 +1,7 @@
import { disableOpacity, enableOpacity } from '~/utils'; import { disableOpacity, enableOpacity, syncOpacity } from '~/utils';
const OVERLAY_SELECTOR = '[data-slot="overlay"]'; const OVERLAY_SELECTOR = '[data-slot="overlay"]';
const SETTINGS_PANEL_SELECTOR = '.yt-settings-panel';
export default defineNuxtPlugin(() => { export default defineNuxtPlugin(() => {
if (import.meta.server) { if (import.meta.server) {
@ -11,7 +12,19 @@ export default defineNuxtPlugin(() => {
let isLocked = false; let isLocked = false;
const syncOverlayOpacity = (): void => { const syncOverlayOpacity = (): void => {
const hasOverlay = document.querySelector(OVERLAY_SELECTOR) !== null; const overlays = Array.from(document.querySelectorAll(OVERLAY_SELECTOR));
const hasOverlay = overlays.length > 0;
const isSettingsOnlyOverlay =
overlays.length === 1 && document.querySelector(SETTINGS_PANEL_SELECTOR) !== null;
if (isSettingsOnlyOverlay) {
if (isLocked) {
enableOpacity();
isLocked = false;
}
return;
}
if (hasOverlay && !isLocked) { if (hasOverlay && !isLocked) {
disableOpacity(); disableOpacity();
@ -19,6 +32,11 @@ export default defineNuxtPlugin(() => {
return; return;
} }
if (hasOverlay) {
syncOpacity();
return;
}
if (!hasOverlay && isLocked) { if (!hasOverlay && isLocked) {
enableOpacity(); enableOpacity();
isLocked = false; isLocked = false;
@ -40,18 +58,4 @@ export default defineNuxtPlugin(() => {
} else { } else {
startObserver(); startObserver();
} }
window.addEventListener(
'beforeunload',
() => {
observer?.disconnect();
observer = null;
if (isLocked) {
enableOpacity();
isLocked = false;
}
},
{ once: true },
);
}); });

View file

@ -742,10 +742,33 @@ const setBodyOpacity = (value: string): boolean => {
return false; return false;
} }
body.setAttribute('style', `opacity: ${value}`); body.style.opacity = value;
return true; return true;
}; };
const clearBodyOpacity = (): boolean => {
const body = document.querySelector('body');
if (!body) {
return false;
}
body.style.removeProperty('opacity');
return true;
};
const syncOpacity = (): boolean => {
if (!getStorageValue<boolean>('random_bg', true, false)) {
opacityLockCount = 0;
return clearBodyOpacity();
}
if (opacityLockCount > 0) {
return setBodyOpacity('1.0');
}
return setBodyOpacity(String(getStorageValue<number>('random_bg_opacity', 0.95)));
};
const disableOpacity = (): boolean => { const disableOpacity = (): boolean => {
if (!getStorageValue<boolean>('random_bg', true, false)) { if (!getStorageValue<boolean>('random_bg', true, false)) {
opacityLockCount = 0; opacityLockCount = 0;
@ -763,11 +786,7 @@ const enableOpacity = (): boolean => {
} }
opacityLockCount = Math.max(0, opacityLockCount - 1); opacityLockCount = Math.max(0, opacityLockCount - 1);
if (opacityLockCount > 0) { return syncOpacity();
return setBodyOpacity('1.0');
}
return setBodyOpacity(String(getStorageValue<number>('random_bg_opacity', 0.95)));
}; };
const stripPath = (base_path: string, real_path: string): string => { const stripPath = (base_path: string, real_path: string): string => {
@ -1028,6 +1047,7 @@ export {
awaiter, awaiter,
encode, encode,
decode, decode,
syncOpacity,
disableOpacity, disableOpacity,
enableOpacity, enableOpacity,
stripPath, stripPath,