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"
:dismissible="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')"
>
<template #header>

View file

@ -923,11 +923,12 @@ onMounted(async () => {
watch(bg_enable, async (v) => await handleImage(v));
watch(simpleMode, () => syncShellModeClass());
watch(bg_opacity, (v) => {
watch(bg_opacity, () => {
if (false === bg_enable.value) {
return;
}
document.querySelector('body')?.setAttribute('style', `opacity: ${v}`);
syncOpacity();
});
watch(loadedImage, () => {
@ -936,7 +937,6 @@ watch(loadedImage, () => {
}
const html = document.documentElement;
const body = document.querySelector('body');
const style = {
'background-color': 'unset',
@ -954,7 +954,7 @@ watch(loadedImage, () => {
.trim(),
);
html.classList.add('bg-fanart');
body?.setAttribute('style', `opacity: ${bg_opacity.value}`);
syncOpacity();
});
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 SETTINGS_PANEL_SELECTOR = '.yt-settings-panel';
export default defineNuxtPlugin(() => {
if (import.meta.server) {
@ -11,7 +12,19 @@ export default defineNuxtPlugin(() => {
let isLocked = false;
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) {
disableOpacity();
@ -19,6 +32,11 @@ export default defineNuxtPlugin(() => {
return;
}
if (hasOverlay) {
syncOpacity();
return;
}
if (!hasOverlay && isLocked) {
enableOpacity();
isLocked = false;
@ -40,18 +58,4 @@ export default defineNuxtPlugin(() => {
} else {
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;
}
body.setAttribute('style', `opacity: ${value}`);
body.style.opacity = value;
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 => {
if (!getStorageValue<boolean>('random_bg', true, false)) {
opacityLockCount = 0;
@ -763,11 +786,7 @@ const enableOpacity = (): boolean => {
}
opacityLockCount = Math.max(0, opacityLockCount - 1);
if (opacityLockCount > 0) {
return setBodyOpacity('1.0');
}
return setBodyOpacity(String(getStorageValue<number>('random_bg_opacity', 0.95)));
return syncOpacity();
};
const stripPath = (base_path: string, real_path: string): string => {
@ -1028,6 +1047,7 @@ export {
awaiter,
encode,
decode,
syncOpacity,
disableOpacity,
enableOpacity,
stripPath,