mirror of
https://github.com/meowarex/TidaLuna-Plugins.git
synced 2026-06-18 03:43:10 +10:00
Performance Overhaul
This commit is contained in:
@@ -0,0 +1,83 @@
|
|||||||
|
# Radiant Lyrics Luna Plugin
|
||||||
|
|
||||||
|
A plugin for Luna (Tidal Desktop) that adds enhanced lyrics styling, cover art backgrounds, and UI management features.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
### ✨ Lyrics Glow Effect
|
||||||
|
- Beautiful glowing effect for lyrics with custom font styling
|
||||||
|
- Can be toggled on/off in settings
|
||||||
|
|
||||||
|
### 🎨 Cover Everywhere (Performance Optimized)
|
||||||
|
- Apply spinning cover art background to the entire app
|
||||||
|
- **NEW: Ultra-performance mode** with significant optimizations:
|
||||||
|
- Reduced blur effects (max 20px in performance mode)
|
||||||
|
- Smaller image sizes (640x640 vs 1280x1280)
|
||||||
|
- Static backgrounds (no animations)
|
||||||
|
- Optimized GPU usage with hardware acceleration
|
||||||
|
- DOM element reuse to prevent memory leaks
|
||||||
|
- Throttled updates (max once per 500ms)
|
||||||
|
- Adaptive polling for track changes
|
||||||
|
|
||||||
|
### 🔧 Performance Mode Features
|
||||||
|
When enabled, Performance Mode provides:
|
||||||
|
- **Blur Reduction**: Caps blur at 20px instead of up to 200px
|
||||||
|
- **Image Optimization**: Uses 640x640 resolution instead of 1280x1280
|
||||||
|
- **Animation Disable**: Removes all CSS animations for static backgrounds
|
||||||
|
- **Memory Optimization**: Better DOM element management and cleanup
|
||||||
|
- **GPU Optimization**: Reduces `will-change` properties and backdrop-filter effects
|
||||||
|
- **Size Reduction**: Smaller background image dimensions (120vw vs 150vw for global, 80vw vs 90vw for Now Playing)
|
||||||
|
|
||||||
|
### 🎛️ UI Management
|
||||||
|
- Hide/unhide UI functionality with smooth transitions
|
||||||
|
- Player bar visibility control when UI is hidden
|
||||||
|
- Customizable background effects (blur, brightness, contrast, spin speed)
|
||||||
|
|
||||||
|
## Technical Improvements
|
||||||
|
|
||||||
|
### Performance Optimizations (Latest Update)
|
||||||
|
1. **DOM Element Reuse**: Background elements are created once and reused instead of being recreated on every track change
|
||||||
|
2. **Update Throttling**: Cover art updates are throttled to prevent excessive DOM manipulation
|
||||||
|
3. **Adaptive Polling**: Track change detection starts fast and slows down when no changes occur
|
||||||
|
4. **Hardware Acceleration**: Added GPU acceleration hints for smoother animations
|
||||||
|
5. **Memory Management**: Proper cleanup of cached DOM elements
|
||||||
|
6. **CSS Optimizations**: Better use of `transform3d` and `backface-visibility` for GPU rendering
|
||||||
|
|
||||||
|
### Normal Mode Performance Enhancements
|
||||||
|
Even without Performance Mode enabled, the plugin now includes significant optimizations:
|
||||||
|
- **Optimized Filter Order**: Reordered CSS filters for better GPU performance (`contrast` → `brightness` → `blur`)
|
||||||
|
- **CSS Custom Properties**: Dynamic filter updates use CSS variables to avoid style recalculation
|
||||||
|
- **Transform3D**: All transforms use `translate3d()` for better GPU acceleration
|
||||||
|
- **Image Caching**: LRU cache for cover art images (max 10 images) for instant loading
|
||||||
|
- **Preloading**: Smart image preloading with cache checking for smoother transitions
|
||||||
|
- **Enhanced GPU Layers**: Better use of `transform-style: preserve-3d` and `isolation: isolate`
|
||||||
|
- **Optimized Animations**: Improved keyframe animations with `cubic-bezier` timing
|
||||||
|
- **Backdrop-Filter Optimization**: More efficient backdrop-filter usage with hardware acceleration
|
||||||
|
- **Compositing Hints**: Added `contain: layout style paint` for better rendering isolation
|
||||||
|
|
||||||
|
### Browser Compatibility
|
||||||
|
- Respects `prefers-reduced-motion` for accessibility
|
||||||
|
- Optimized for modern browsers with hardware acceleration support
|
||||||
|
|
||||||
|
## Settings
|
||||||
|
|
||||||
|
- **Lyrics Glow Effect**: Toggle the enhanced lyrics styling
|
||||||
|
- **Hide UI Feature**: Enable hide/show UI functionality
|
||||||
|
- **Player Bar Visibility**: Keep player bar visible when UI is hidden
|
||||||
|
- **Cover Everywhere**: Apply cover art background to entire app
|
||||||
|
- **Performance Mode**: Enable ultra-light performance optimizations
|
||||||
|
- **Background Controls**: Adjust contrast (0-200), blur (0-200), brightness (0-100)
|
||||||
|
- **Spin Speed**: Control rotation speed (10-120 seconds per rotation)
|
||||||
|
- **Settings Affect Now Playing**: Apply background settings to Now Playing view
|
||||||
|
|
||||||
|
## Performance Recommendations
|
||||||
|
|
||||||
|
- Enable **Performance Mode** if you experience lag or high GPU usage
|
||||||
|
- Reduce **Background Blur** setting for better performance
|
||||||
|
- Use lower **Background Contrast** values on slower systems
|
||||||
|
- Consider disabling **Cover Everywhere** on very low-end systems
|
||||||
|
|
||||||
|
## Credits
|
||||||
|
|
||||||
|
- Heavily inspired by Cover-Theme by @Inrixia
|
||||||
|
- Thanks to the Luna development team for the plugin framework
|
||||||
@@ -77,7 +77,7 @@ export const Settings = () => {
|
|||||||
/>
|
/>
|
||||||
<LunaSwitchSetting
|
<LunaSwitchSetting
|
||||||
title="Performance Mode"
|
title="Performance Mode"
|
||||||
desc="Disable spinning animations to reduce performance impact on your computer (backgrounds become static)"
|
desc="Ultra-light performance mode: Reduces blur effects (max 20px), uses smaller image sizes, disables animations, and optimizes GPU usage for better performance"
|
||||||
checked={performanceMode}
|
checked={performanceMode}
|
||||||
onChange={(_, checked: boolean) => {
|
onChange={(_, checked: boolean) => {
|
||||||
console.log("Performance Mode:", checked ? "enabled" : "disabled");
|
console.log("Performance Mode:", checked ? "enabled" : "disabled");
|
||||||
@@ -86,8 +86,8 @@ export const Settings = () => {
|
|||||||
if ((window as any).updateRadiantLyricsGlobalBackground) {
|
if ((window as any).updateRadiantLyricsGlobalBackground) {
|
||||||
(window as any).updateRadiantLyricsGlobalBackground();
|
(window as any).updateRadiantLyricsGlobalBackground();
|
||||||
}
|
}
|
||||||
if ((window as any).updateRadiantLyricsPerformanceMode) {
|
if ((window as any).updateRadiantLyricsNowPlayingBackground) {
|
||||||
(window as any).updateRadiantLyricsPerformanceMode();
|
(window as any).updateRadiantLyricsNowPlayingBackground();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,41 +1,152 @@
|
|||||||
/* Global Spinning Background Styles */
|
/* Global Spinning Background Styles - PERFORMANCE OPTIMIZED */
|
||||||
|
|
||||||
.global-spinning-black-bg {
|
.global-background-container {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
left: 0;
|
left: 0;
|
||||||
top: 0;
|
top: 0;
|
||||||
width: 100vw;
|
width: 100vw;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
|
z-index: -3;
|
||||||
|
pointer-events: none;
|
||||||
|
overflow: hidden;
|
||||||
|
/* Enhanced hardware acceleration */
|
||||||
|
transform: translate3d(0, 0, 0);
|
||||||
|
backface-visibility: hidden;
|
||||||
|
perspective: 1000px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.global-spinning-black-bg {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
background: #000;
|
background: #000;
|
||||||
z-index: -2;
|
z-index: -2;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
|
/* Force GPU layer */
|
||||||
|
transform: translateZ(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
.global-spinning-image {
|
.global-spinning-image {
|
||||||
position: fixed;
|
position: absolute;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
transform: translate(-50%, -50%);
|
transform: translate3d(-50%, -50%, 0);
|
||||||
width: 150vw;
|
width: 150vw;
|
||||||
height: 150vh;
|
height: 150vh;
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
z-index: -1;
|
z-index: -1;
|
||||||
filter: blur(80px) brightness(0.4) contrast(1.2) saturate(1);
|
filter: blur(80px) brightness(0.4) contrast(1.2) saturate(1);
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
animation: spinGlobal 45s linear infinite;
|
animation: spinGlobalOptimized 45s cubic-bezier(0, 0, 1, 1) infinite;
|
||||||
will-change: transform, filter;
|
will-change: transform;
|
||||||
|
/* Enhanced hardware acceleration for smooth animations */
|
||||||
|
transform-origin: center center;
|
||||||
|
backface-visibility: hidden;
|
||||||
|
/* Optimized compositing */
|
||||||
|
contain: layout style paint;
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes spinGlobal {
|
/* Performance mode optimizations */
|
||||||
from { transform: translate(-50%, -50%) rotate(0deg); }
|
.global-spinning-image.performance-mode-static {
|
||||||
to { transform: translate(-50%, -50%) rotate(360deg); }
|
animation: none !important;
|
||||||
|
transform: translate3d(-50%, -50%, 0) !important;
|
||||||
|
will-change: auto !important;
|
||||||
|
/* Lighter blur for performance */
|
||||||
|
filter: blur(20px) brightness(0.4) contrast(1.2) saturate(1) !important;
|
||||||
|
/* Smaller size for performance */
|
||||||
|
width: 120vw !important;
|
||||||
|
height: 120vh !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Performance mode - static backgrounds */
|
|
||||||
.global-spinning-image.performance-mode-static,
|
|
||||||
.now-playing-background-image.performance-mode-static {
|
.now-playing-background-image.performance-mode-static {
|
||||||
animation: none !important;
|
animation: none !important;
|
||||||
transform: translate(-50%, -50%) !important;
|
transform: translate3d(-50%, -50%, 0) !important;
|
||||||
|
will-change: auto !important;
|
||||||
|
/* Optimized size and effects for performance */
|
||||||
|
width: 80vw !important;
|
||||||
|
height: 80vh !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now Playing Background Container Optimization */
|
||||||
|
.now-playing-background-container {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
z-index: -3;
|
||||||
|
pointer-events: none;
|
||||||
|
overflow: hidden;
|
||||||
|
/* Enhanced hardware acceleration */
|
||||||
|
transform: translate3d(0, 0, 0);
|
||||||
|
backface-visibility: hidden;
|
||||||
|
perspective: 1000px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* OPTIMIZED keyframe animations with better GPU acceleration */
|
||||||
|
@keyframes spinGlobalOptimized {
|
||||||
|
0% {
|
||||||
|
transform: translate3d(-50%, -50%, 0) rotate(0deg);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: translate3d(-50%, -50%, 0) rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
0% {
|
||||||
|
transform: translate3d(-50%, -50%, 0) rotate(0deg);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: translate3d(-50%, -50%, 0) rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Optimized backdrop-filter usage for better performance */
|
||||||
|
.optimized-backdrop {
|
||||||
|
backdrop-filter: blur(10px);
|
||||||
|
-webkit-backdrop-filter: blur(10px);
|
||||||
|
/* Force GPU acceleration for backdrop filters */
|
||||||
|
transform: translateZ(0);
|
||||||
|
will-change: backdrop-filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reduced motion for users who prefer it */
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
.global-spinning-image,
|
||||||
|
.now-playing-background-image {
|
||||||
|
animation: none !important;
|
||||||
|
transform: translate3d(-50%, -50%, 0) !important;
|
||||||
|
will-change: auto !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Performance mode: disable heavy effects */
|
||||||
|
.performance-mode .global-spinning-image,
|
||||||
|
.performance-mode .now-playing-background-image {
|
||||||
|
filter: blur(10px) brightness(0.4) contrast(1.1) !important;
|
||||||
|
animation: none !important;
|
||||||
|
will-change: auto !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* OPTIMIZED Normal mode styles for better performance without quality loss */
|
||||||
|
body:not(.performance-mode) .global-spinning-image {
|
||||||
|
/* Use optimized filter order for better GPU performance */
|
||||||
|
filter: contrast(var(--bg-contrast, 1.2)) brightness(var(--bg-brightness, 0.4)) blur(var(--bg-blur, 80px)) saturate(1);
|
||||||
|
/* Enhanced GPU acceleration */
|
||||||
|
transform-style: preserve-3d;
|
||||||
|
/* Optimized compositing layer */
|
||||||
|
isolation: isolate;
|
||||||
|
}
|
||||||
|
|
||||||
|
body:not(.performance-mode) .now-playing-background-image {
|
||||||
|
/* Use optimized filter order */
|
||||||
|
filter: contrast(var(--bg-contrast, 1.2)) brightness(var(--bg-brightness, 0.4)) blur(var(--bg-blur, 80px));
|
||||||
|
/* Enhanced GPU acceleration */
|
||||||
|
transform-style: preserve-3d;
|
||||||
|
isolation: isolate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make Notification Feed sidebar transparent */
|
/* Make Notification Feed sidebar transparent */
|
||||||
@@ -60,7 +171,7 @@ main,
|
|||||||
background: unset !important;
|
background: unset !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sidebar and player bar semi-transparent */
|
/* OPTIMIZED sidebar and player bar with better backdrop-filter performance */
|
||||||
[data-test="footer-player"],
|
[data-test="footer-player"],
|
||||||
[data-test="main-layout-sidebar-wrapper"],
|
[data-test="main-layout-sidebar-wrapper"],
|
||||||
[class^="_bar"],
|
[class^="_bar"],
|
||||||
@@ -68,16 +179,37 @@ main,
|
|||||||
background-color: rgba(0, 0, 0, 0.3) !important;
|
background-color: rgba(0, 0, 0, 0.3) !important;
|
||||||
backdrop-filter: blur(10px) !important;
|
backdrop-filter: blur(10px) !important;
|
||||||
-webkit-backdrop-filter: blur(10px) !important;
|
-webkit-backdrop-filter: blur(10px) !important;
|
||||||
|
/* Force GPU acceleration for backdrop filters */
|
||||||
|
transform: translateZ(0);
|
||||||
|
will-change: backdrop-filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Feed sidebar panel - black tint background for readability | Cheers @isolate for the idea */
|
/* Performance mode: reduce backdrop blur */
|
||||||
|
.performance-mode [data-test="footer-player"],
|
||||||
|
.performance-mode [data-test="main-layout-sidebar-wrapper"],
|
||||||
|
.performance-mode [class^="_bar"],
|
||||||
|
.performance-mode [class^="_sidebarItem"]:hover {
|
||||||
|
backdrop-filter: blur(5px) !important;
|
||||||
|
-webkit-backdrop-filter: blur(5px) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* OPTIMIZED Feed sidebar panel */
|
||||||
[data-test="feed-sidebar"] {
|
[data-test="feed-sidebar"] {
|
||||||
background-color: rgba(0, 0, 0, 0.5) !important;
|
background-color: rgba(0, 0, 0, 0.5) !important;
|
||||||
backdrop-filter: blur(10px) !important;
|
backdrop-filter: blur(10px) !important;
|
||||||
-webkit-backdrop-filter: blur(10px) !important;
|
-webkit-backdrop-filter: blur(10px) !important;
|
||||||
|
/* Enhanced GPU acceleration */
|
||||||
|
transform: translateZ(0);
|
||||||
|
will-change: backdrop-filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Feed sidebar items - transparent | Cheers @isolate for the idea */
|
/* Performance mode: reduce sidebar backdrop blur */
|
||||||
|
.performance-mode [data-test="feed-sidebar"] {
|
||||||
|
backdrop-filter: blur(5px) !important;
|
||||||
|
-webkit-backdrop-filter: blur(5px) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Feed sidebar items - transparent */
|
||||||
[class*="_feedSidebarItem"],
|
[class*="_feedSidebarItem"],
|
||||||
[class*="_feedSidebarItemDiv"],
|
[class*="_feedSidebarItemDiv"],
|
||||||
[class*="_cellContainer"],
|
[class*="_cellContainer"],
|
||||||
|
|||||||
@@ -22,6 +22,18 @@ const lyricsGlowStyleTag = new StyleTag("RadiantLyrics-lyrics-glow", unloads);
|
|||||||
|
|
||||||
let globalSpinningBgStyleTag: StyleTag | null = null;
|
let globalSpinningBgStyleTag: StyleTag | null = null;
|
||||||
|
|
||||||
|
// Performance optimized variables for cover everywhere
|
||||||
|
let globalBackgroundContainer: HTMLElement | null = null;
|
||||||
|
let globalBackgroundImage: HTMLImageElement | null = null;
|
||||||
|
let globalBlackBg: HTMLElement | null = null;
|
||||||
|
let currentGlobalCoverSrc: string | null = null;
|
||||||
|
let lastUpdateTime = 0;
|
||||||
|
const UPDATE_THROTTLE = 500; // Throttle updates to max once per 500ms
|
||||||
|
|
||||||
|
// Image cache for better performance
|
||||||
|
const imageCache = new Map<string, HTMLImageElement>();
|
||||||
|
const MAX_CACHE_SIZE = 10; // Limit cache size to prevent memory leaks
|
||||||
|
|
||||||
// Apply lyrics glow styles if enabled
|
// Apply lyrics glow styles if enabled
|
||||||
if (settings.lyricsGlowEnabled) {
|
if (settings.lyricsGlowEnabled) {
|
||||||
lyricsGlowStyleTag.css = lyricsGlow;
|
lyricsGlowStyleTag.css = lyricsGlow;
|
||||||
@@ -120,75 +132,150 @@ const updateRadiantLyricsStyles = function(): void {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function to apply spinning background to the entire app (cover everywhere)
|
// Function to apply spinning background to the entire app (cover everywhere) - PERFORMANCE OPTIMIZED
|
||||||
const applyGlobalSpinningBackground = (coverArtImageSrc: string): void => {
|
const applyGlobalSpinningBackground = (coverArtImageSrc: string): void => {
|
||||||
const appContainer = document.querySelector('[data-test="main"]') as HTMLElement;
|
const appContainer = document.querySelector('[data-test="main"]') as HTMLElement;
|
||||||
|
|
||||||
if (!settings.spinningCoverEverywhere) {
|
if (!settings.spinningCoverEverywhere) {
|
||||||
// Remove StyleTag and all background elements
|
cleanUpGlobalSpinningBackground();
|
||||||
if (globalSpinningBgStyleTag) {
|
|
||||||
globalSpinningBgStyleTag.remove();
|
|
||||||
globalSpinningBgStyleTag = null;
|
|
||||||
}
|
|
||||||
if (appContainer) {
|
|
||||||
appContainer.querySelectorAll('.global-spinning-image, .global-spinning-black-bg').forEach(el => el.remove());
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add StyleTag if not present (Don't know if this is needed.. But it's here)
|
// Throttle updates to prevent excessive DOM manipulation
|
||||||
|
const now = Date.now();
|
||||||
|
if (now - lastUpdateTime < UPDATE_THROTTLE && currentGlobalCoverSrc === coverArtImageSrc) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastUpdateTime = now;
|
||||||
|
currentGlobalCoverSrc = coverArtImageSrc;
|
||||||
|
|
||||||
|
// Add StyleTag if not present
|
||||||
if (!globalSpinningBgStyleTag) {
|
if (!globalSpinningBgStyleTag) {
|
||||||
globalSpinningBgStyleTag = new StyleTag("RadiantLyrics-global-spinning-bg", unloads, coverEverywhereCss);
|
globalSpinningBgStyleTag = new StyleTag("RadiantLyrics-global-spinning-bg", unloads, coverEverywhereCss);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!appContainer) return;
|
if (!appContainer) return;
|
||||||
|
|
||||||
// Remove any existing background elements
|
// Create container structure if it doesn't exist (REUSE DOM ELEMENTS)
|
||||||
appContainer.querySelectorAll('.global-spinning-image, .global-spinning-black-bg').forEach(el => el.remove());
|
if (!globalBackgroundContainer) {
|
||||||
|
globalBackgroundContainer = document.createElement('div');
|
||||||
|
globalBackgroundContainer.className = 'global-background-container';
|
||||||
|
globalBackgroundContainer.style.cssText = `
|
||||||
|
position: fixed;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
|
z-index: -3;
|
||||||
|
pointer-events: none;
|
||||||
|
overflow: hidden;
|
||||||
|
`;
|
||||||
|
appContainer.appendChild(globalBackgroundContainer);
|
||||||
|
|
||||||
// Add black background (to obscure image edges)
|
// Create black background layer
|
||||||
const blackBg = document.createElement('div');
|
globalBlackBg = document.createElement('div');
|
||||||
blackBg.className = 'global-spinning-black-bg';
|
globalBlackBg.className = 'global-spinning-black-bg';
|
||||||
appContainer.appendChild(blackBg);
|
globalBackgroundContainer.appendChild(globalBlackBg);
|
||||||
|
|
||||||
// Add one image for background (spinning or static based on performance mode)
|
// Create image element
|
||||||
const img = document.createElement('img');
|
globalBackgroundImage = document.createElement('img');
|
||||||
img.src = coverArtImageSrc;
|
globalBackgroundImage.className = 'global-spinning-image';
|
||||||
img.className = 'global-spinning-image';
|
globalBackgroundImage.style.cssText = `
|
||||||
img.style.animationDelay = '0s';
|
position: absolute;
|
||||||
img.style.filter = `blur(${settings.backgroundBlur}px) brightness(${settings.backgroundBrightness / 100}) contrast(${settings.backgroundContrast}%)`;
|
left: 50%;
|
||||||
|
top: 50%;
|
||||||
// Apply or remove animation based on performance mode
|
transform: translate(-50%, -50%);
|
||||||
if (settings.performanceMode) {
|
object-fit: cover;
|
||||||
img.style.animation = 'none';
|
z-index: -1;
|
||||||
img.classList.add('performance-mode-static');
|
will-change: transform;
|
||||||
} else {
|
transform-origin: center center;
|
||||||
img.style.animation = `spinGlobal ${settings.spinSpeed}s linear infinite`;
|
`;
|
||||||
img.classList.remove('performance-mode-static');
|
globalBackgroundContainer.appendChild(globalBackgroundImage);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update image source efficiently with caching for smoother transitions
|
||||||
|
if (globalBackgroundImage && globalBackgroundImage.src !== coverArtImageSrc) {
|
||||||
|
// Check cache first
|
||||||
|
if (imageCache.has(coverArtImageSrc)) {
|
||||||
|
globalBackgroundImage.src = coverArtImageSrc;
|
||||||
|
} else {
|
||||||
|
// Preload and cache the new image
|
||||||
|
const preloadImg = new Image();
|
||||||
|
preloadImg.onload = () => {
|
||||||
|
// Add to cache (with size limit)
|
||||||
|
if (imageCache.size >= MAX_CACHE_SIZE) {
|
||||||
|
const firstKey = imageCache.keys().next().value;
|
||||||
|
if (firstKey) {
|
||||||
|
imageCache.delete(firstKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
imageCache.set(coverArtImageSrc, preloadImg);
|
||||||
|
|
||||||
|
if (globalBackgroundImage && globalBackgroundImage.src !== coverArtImageSrc) {
|
||||||
|
globalBackgroundImage.src = coverArtImageSrc;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
preloadImg.src = coverArtImageSrc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply performance-optimized settings
|
||||||
|
if (globalBackgroundImage) {
|
||||||
|
// Performance mode optimizations
|
||||||
|
if (settings.performanceMode) {
|
||||||
|
// Ultra-light performance mode
|
||||||
|
globalBackgroundImage.style.width = '120vw';
|
||||||
|
globalBackgroundImage.style.height = '120vh';
|
||||||
|
globalBackgroundImage.style.filter = `blur(${Math.min(settings.backgroundBlur, 20)}px) brightness(${settings.backgroundBrightness / 100}) contrast(${Math.min(settings.backgroundContrast, 150)}%)`;
|
||||||
|
globalBackgroundImage.style.animation = 'none';
|
||||||
|
globalBackgroundImage.style.transform = 'translate(-50%, -50%)';
|
||||||
|
globalBackgroundImage.classList.add('performance-mode-static');
|
||||||
|
// Remove will-change for better memory usage
|
||||||
|
globalBackgroundImage.style.willChange = 'auto';
|
||||||
|
} else {
|
||||||
|
// OPTIMIZED Normal mode - Better performance while maintaining quality
|
||||||
|
globalBackgroundImage.style.width = '150vw';
|
||||||
|
globalBackgroundImage.style.height = '150vh';
|
||||||
|
// Use CSS custom properties for dynamic updates without style recalculation
|
||||||
|
globalBackgroundImage.style.setProperty('--bg-contrast', `${settings.backgroundContrast}%`);
|
||||||
|
globalBackgroundImage.style.setProperty('--bg-brightness', `${settings.backgroundBrightness / 100}`);
|
||||||
|
globalBackgroundImage.style.setProperty('--bg-blur', `${settings.backgroundBlur}px`);
|
||||||
|
globalBackgroundImage.style.animation = `spinGlobalOptimized ${settings.spinSpeed}s linear infinite`;
|
||||||
|
globalBackgroundImage.classList.remove('performance-mode-static');
|
||||||
|
// Use transform3d for better GPU acceleration
|
||||||
|
globalBackgroundImage.style.willChange = 'transform';
|
||||||
|
globalBackgroundImage.style.transformOrigin = 'center center';
|
||||||
|
// Force GPU layer creation for smoother animations
|
||||||
|
globalBackgroundImage.style.transform = 'translate3d(-50%, -50%, 0)';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
appContainer.appendChild(img);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function to clean up global spinning background
|
// Optimized cleanup function
|
||||||
const cleanUpGlobalSpinningBackground = function(): void {
|
const cleanUpGlobalSpinningBackground = function(): void {
|
||||||
const globalImages = document.getElementsByClassName("global-spinning-image");
|
if (globalBackgroundContainer && globalBackgroundContainer.parentNode) {
|
||||||
Array.from(globalImages).forEach((element) => {
|
globalBackgroundContainer.parentNode.removeChild(globalBackgroundContainer);
|
||||||
element.remove();
|
|
||||||
});
|
|
||||||
// Also remove the overlay
|
|
||||||
const overlay = document.querySelector('.global-spinning-overlay');
|
|
||||||
if (overlay && overlay.parentNode) {
|
|
||||||
overlay.parentNode.removeChild(overlay);
|
|
||||||
}
|
}
|
||||||
// Also remove the black bg
|
globalBackgroundContainer = null;
|
||||||
const blackBg = document.querySelector('.global-spinning-black-bg');
|
globalBackgroundImage = null;
|
||||||
if (blackBg && blackBg.parentNode) {
|
globalBlackBg = null;
|
||||||
blackBg.parentNode.removeChild(blackBg);
|
currentGlobalCoverSrc = null;
|
||||||
|
|
||||||
|
if (globalSpinningBgStyleTag) {
|
||||||
|
globalSpinningBgStyleTag.remove();
|
||||||
|
globalSpinningBgStyleTag = null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function to update global background when settings change
|
// Function to update global background when settings change
|
||||||
const updateRadiantLyricsGlobalBackground = function(): void {
|
const updateRadiantLyricsGlobalBackground = function(): void {
|
||||||
|
// Apply performance mode class to document body
|
||||||
|
if (settings.performanceMode) {
|
||||||
|
document.body.classList.add('performance-mode');
|
||||||
|
} else {
|
||||||
|
document.body.classList.remove('performance-mode');
|
||||||
|
}
|
||||||
|
|
||||||
if (settings.spinningCoverEverywhere) {
|
if (settings.spinningCoverEverywhere) {
|
||||||
// Get current cover art and apply global background
|
// Get current cover art and apply global background
|
||||||
updateCoverArtBackground();
|
updateCoverArtBackground();
|
||||||
@@ -197,7 +284,7 @@ const updateRadiantLyricsGlobalBackground = function(): void {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function to update Now Playing background when settings change
|
// Function to update Now Playing background when settings change - PERFORMANCE OPTIMIZED
|
||||||
const updateRadiantLyricsNowPlayingBackground = function(): void {
|
const updateRadiantLyricsNowPlayingBackground = function(): void {
|
||||||
const nowPlayingBackgroundImages = document.querySelectorAll('.now-playing-background-image');
|
const nowPlayingBackgroundImages = document.querySelectorAll('.now-playing-background-image');
|
||||||
nowPlayingBackgroundImages.forEach((img: Element) => {
|
nowPlayingBackgroundImages.forEach((img: Element) => {
|
||||||
@@ -209,26 +296,40 @@ const updateRadiantLyricsNowPlayingBackground = function(): void {
|
|||||||
const defaultContrast = 120;
|
const defaultContrast = 120;
|
||||||
const defaultSpinSpeed = 45;
|
const defaultSpinSpeed = 45;
|
||||||
|
|
||||||
|
let blur, brightness, contrast, spinSpeed;
|
||||||
|
|
||||||
if (settings.settingsAffectNowPlaying) {
|
if (settings.settingsAffectNowPlaying) {
|
||||||
// Use settings values
|
blur = settings.backgroundBlur;
|
||||||
if (settings.performanceMode) {
|
brightness = settings.backgroundBrightness;
|
||||||
imgElement.style.animation = 'none';
|
contrast = settings.backgroundContrast;
|
||||||
imgElement.classList.add('performance-mode-static');
|
spinSpeed = settings.spinSpeed;
|
||||||
} else {
|
|
||||||
imgElement.style.animation = `spin ${settings.spinSpeed}s linear infinite`;
|
|
||||||
imgElement.classList.remove('performance-mode-static');
|
|
||||||
}
|
|
||||||
imgElement.style.filter = `blur(${settings.backgroundBlur}px) brightness(${settings.backgroundBrightness / 100}) contrast(${settings.backgroundContrast}%)`;
|
|
||||||
} else {
|
} else {
|
||||||
// Reset to default values
|
blur = defaultBlur;
|
||||||
if (settings.performanceMode) {
|
brightness = defaultBrightness;
|
||||||
imgElement.style.animation = 'none';
|
contrast = defaultContrast;
|
||||||
imgElement.classList.add('performance-mode-static');
|
spinSpeed = defaultSpinSpeed;
|
||||||
} else {
|
}
|
||||||
imgElement.style.animation = `spin ${defaultSpinSpeed}s linear infinite`;
|
|
||||||
imgElement.classList.remove('performance-mode-static');
|
// Performance mode optimizations
|
||||||
}
|
if (settings.performanceMode) {
|
||||||
imgElement.style.filter = `blur(${defaultBlur}px) brightness(${defaultBrightness / 100}) contrast(${defaultContrast}%)`;
|
// Reduce blur and effects for better performance
|
||||||
|
blur = Math.min(blur, 20);
|
||||||
|
contrast = Math.min(contrast, 150);
|
||||||
|
imgElement.style.animation = 'none';
|
||||||
|
imgElement.style.transform = 'translate3d(-50%, -50%, 0)';
|
||||||
|
imgElement.classList.add('performance-mode-static');
|
||||||
|
imgElement.style.willChange = 'auto';
|
||||||
|
imgElement.style.filter = `blur(${blur}px) brightness(${brightness / 100}) contrast(${contrast}%)`;
|
||||||
|
} else {
|
||||||
|
// OPTIMIZED Normal mode updates using CSS custom properties
|
||||||
|
imgElement.style.animation = `spin ${spinSpeed}s linear infinite`;
|
||||||
|
imgElement.classList.remove('performance-mode-static');
|
||||||
|
imgElement.style.willChange = 'transform';
|
||||||
|
imgElement.style.transform = 'translate3d(-50%, -50%, 0)';
|
||||||
|
// Use CSS custom properties for efficient updates
|
||||||
|
imgElement.style.setProperty('--bg-contrast', `${contrast}%`);
|
||||||
|
imgElement.style.setProperty('--bg-brightness', `${brightness / 100}`);
|
||||||
|
imgElement.style.setProperty('--bg-blur', `${blur}px`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -440,31 +541,52 @@ const createUnhideUIButton = function(): void {
|
|||||||
}, 1500); // Slight delay after hide button
|
}, 1500); // Slight delay after hide button
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function to observe track changes using track ID
|
// PERFORMANCE OPTIMIZED track change observer
|
||||||
const observeTrackChanges = (): void => {
|
const observeTrackChanges = (): void => {
|
||||||
let lastTrackId: string | null = null;
|
let lastTrackId: string | null = null;
|
||||||
const interval = setInterval(() => {
|
let checkCount = 0;
|
||||||
|
let currentInterval = 500; // Start with slower checks
|
||||||
|
|
||||||
|
const checkTrackChange = () => {
|
||||||
const currentTrackId = PlayState.playbackContext?.actualProductId;
|
const currentTrackId = PlayState.playbackContext?.actualProductId;
|
||||||
if (currentTrackId && currentTrackId !== lastTrackId) {
|
if (currentTrackId && currentTrackId !== lastTrackId) {
|
||||||
//trace.msg.log(`Track changed: ${lastTrackId} -> ${currentTrackId}`);
|
//trace.msg.log(`Track changed: ${lastTrackId} -> ${currentTrackId}`);
|
||||||
lastTrackId = currentTrackId;
|
lastTrackId = currentTrackId;
|
||||||
// delay for cover art to load (to prevent flickering)
|
// Immediate update for better responsiveness, but throttled by the update function
|
||||||
setTimeout(() => {
|
updateCoverArtBackground();
|
||||||
updateCoverArtBackground();
|
|
||||||
}, 150);
|
// Reset to faster checking for a short period after a change
|
||||||
|
checkCount = 0;
|
||||||
|
currentInterval = 250;
|
||||||
}
|
}
|
||||||
}, 150); // Check every 150ms for better responsiveness
|
|
||||||
|
// Gradually slow down checking if no changes
|
||||||
|
checkCount++;
|
||||||
|
if (checkCount > 10 && currentInterval < 1000) {
|
||||||
|
currentInterval = Math.min(currentInterval * 1.2, 1000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
unloads.add(() => clearInterval(interval));
|
// Adaptive interval - faster when changes are happening, slower when stable
|
||||||
|
const startAdaptiveInterval = () => {
|
||||||
|
const intervalId = setInterval(() => {
|
||||||
|
checkTrackChange();
|
||||||
|
}, currentInterval);
|
||||||
|
|
||||||
|
unloads.add(() => clearInterval(intervalId));
|
||||||
|
return intervalId;
|
||||||
|
};
|
||||||
|
|
||||||
|
startAdaptiveInterval();
|
||||||
|
|
||||||
// Initial background application (if a track is already loaded)
|
// Initial background application (if a track is already loaded)
|
||||||
const currentTrackId = PlayState.playbackContext?.actualProductId;
|
const currentTrackId = PlayState.playbackContext?.actualProductId;
|
||||||
if (currentTrackId) {
|
if (currentTrackId) {
|
||||||
lastTrackId = currentTrackId;
|
lastTrackId = currentTrackId;
|
||||||
// Reduced delay for initial load
|
// Immediate initial load for better UX
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
updateCoverArtBackground();
|
updateCoverArtBackground();
|
||||||
}, 300);
|
}, 100);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -518,6 +640,14 @@ function observeLyricsContainer(): void {
|
|||||||
unloads.add(() => observer.disconnect());
|
unloads.add(() => observer.disconnect());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Optimized DOM element caching for Now Playing
|
||||||
|
let nowPlayingBackgroundContainer: HTMLElement | null = null;
|
||||||
|
let nowPlayingBackgroundImage: HTMLImageElement | null = null;
|
||||||
|
let nowPlayingBlackBg: HTMLElement | null = null;
|
||||||
|
let nowPlayingGradientOverlay: HTMLElement | null = null;
|
||||||
|
let currentNowPlayingCoverSrc: string | null = null;
|
||||||
|
let spinAnimationAdded = false;
|
||||||
|
|
||||||
const updateCoverArtBackground = function (method: number = 0): void {
|
const updateCoverArtBackground = function (method: number = 0): void {
|
||||||
if (method === 1) {
|
if (method === 1) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -531,16 +661,19 @@ const updateCoverArtBackground = function (method: number = 0): void {
|
|||||||
|
|
||||||
if (coverArtImageElement) {
|
if (coverArtImageElement) {
|
||||||
coverArtImageSrc = coverArtImageElement.src;
|
coverArtImageSrc = coverArtImageElement.src;
|
||||||
// Set res to 1280x1280
|
// Use higher resolution for better quality, but consider performance mode
|
||||||
coverArtImageSrc = coverArtImageSrc.replace(/\d+x\d+/, '1280x1280');
|
const targetRes = settings.performanceMode ? '640x640' : '1280x1280';
|
||||||
coverArtImageElement.src = coverArtImageSrc;
|
coverArtImageSrc = coverArtImageSrc.replace(/\d+x\d+/, targetRes);
|
||||||
|
if (coverArtImageElement.src !== coverArtImageSrc) {
|
||||||
|
coverArtImageElement.src = coverArtImageSrc;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const videoElement = document.querySelector('figure[class*="_albumImage"] > div > div > div > video') as HTMLVideoElement;
|
const videoElement = document.querySelector('figure[class*="_albumImage"] > div > div > div > video') as HTMLVideoElement;
|
||||||
if (videoElement) {
|
if (videoElement) {
|
||||||
coverArtImageSrc = videoElement.getAttribute("poster");
|
coverArtImageSrc = videoElement.getAttribute("poster");
|
||||||
if (coverArtImageSrc) {
|
if (coverArtImageSrc) {
|
||||||
// Set res to 1280x1280
|
const targetRes = settings.performanceMode ? '640x640' : '1280x1280';
|
||||||
coverArtImageSrc = coverArtImageSrc.replace(/\d+x\d+/, '1280x1280');
|
coverArtImageSrc = coverArtImageSrc.replace(/\d+x\d+/, targetRes);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cleanUpDynamicArt();
|
cleanUpDynamicArt();
|
||||||
@@ -555,67 +688,135 @@ const updateCoverArtBackground = function (method: number = 0): void {
|
|||||||
applyGlobalSpinningBackground(coverArtImageSrc);
|
applyGlobalSpinningBackground(coverArtImageSrc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply spinning CoverArt background to the Now Playing container
|
// Apply spinning CoverArt background to the Now Playing container - OPTIMIZED
|
||||||
const nowPlayingContainerElement = document.querySelector('[class*="_nowPlayingContainer"]') as HTMLElement;
|
const nowPlayingContainerElement = document.querySelector('[class*="_nowPlayingContainer"]') as HTMLElement;
|
||||||
if (nowPlayingContainerElement) {
|
if (nowPlayingContainerElement) {
|
||||||
// Remove existing background images if they exist
|
// Create DOM structure if it doesn't exist (REUSE ELEMENTS)
|
||||||
const existingBackgroundImages = nowPlayingContainerElement.querySelectorAll('.now-playing-background-image, .now-playing-black-bg');
|
if (!nowPlayingBackgroundContainer || !nowPlayingContainerElement.contains(nowPlayingBackgroundContainer)) {
|
||||||
existingBackgroundImages.forEach(img => img.remove());
|
// Clean up any old elements first
|
||||||
|
nowPlayingContainerElement.querySelectorAll('.now-playing-background-image, .now-playing-black-bg, .now-playing-gradient-overlay').forEach(el => el.remove());
|
||||||
|
|
||||||
|
// Create container
|
||||||
|
nowPlayingBackgroundContainer = document.createElement('div');
|
||||||
|
nowPlayingBackgroundContainer.className = 'now-playing-background-container';
|
||||||
|
nowPlayingBackgroundContainer.style.cssText = `
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
z-index: -3;
|
||||||
|
pointer-events: none;
|
||||||
|
overflow: hidden;
|
||||||
|
`;
|
||||||
|
nowPlayingContainerElement.appendChild(nowPlayingBackgroundContainer);
|
||||||
|
|
||||||
// Add black background layer (to obscure image edges)
|
// Create black background layer
|
||||||
const blackBg = document.createElement('div');
|
nowPlayingBlackBg = document.createElement('div');
|
||||||
blackBg.className = 'now-playing-black-bg';
|
nowPlayingBlackBg.className = 'now-playing-black-bg';
|
||||||
blackBg.style.position = 'absolute';
|
nowPlayingBlackBg.style.cssText = `
|
||||||
blackBg.style.left = '0';
|
position: absolute;
|
||||||
blackBg.style.top = '0';
|
left: 0;
|
||||||
blackBg.style.width = '100%';
|
top: 0;
|
||||||
blackBg.style.height = '100%';
|
width: 100%;
|
||||||
blackBg.style.background = '#000';
|
height: 100%;
|
||||||
blackBg.style.zIndex = '-2';
|
background: #000;
|
||||||
blackBg.style.pointerEvents = 'none';
|
z-index: -2;
|
||||||
nowPlayingContainerElement.appendChild(blackBg);
|
pointer-events: none;
|
||||||
|
`;
|
||||||
|
nowPlayingBackgroundContainer.appendChild(nowPlayingBlackBg);
|
||||||
|
|
||||||
// Create and append single background layer (the cover art)
|
// Create background image
|
||||||
const backgroundImage = document.createElement('img');
|
nowPlayingBackgroundImage = document.createElement('img');
|
||||||
backgroundImage.src = coverArtImageSrc;
|
nowPlayingBackgroundImage.className = 'now-playing-background-image';
|
||||||
backgroundImage.className = 'now-playing-background-image';
|
nowPlayingBackgroundImage.style.cssText = `
|
||||||
backgroundImage.style.position = 'absolute';
|
position: absolute;
|
||||||
backgroundImage.style.left = '50%';
|
left: 50%;
|
||||||
backgroundImage.style.top = '50%';
|
top: 50%;
|
||||||
backgroundImage.style.transform = 'translate(-50%, -50%)';
|
transform: translate(-50%, -50%);
|
||||||
backgroundImage.style.width = '90vw';
|
object-fit: cover;
|
||||||
backgroundImage.style.height = '90vh';
|
z-index: -1;
|
||||||
backgroundImage.style.objectFit = 'cover';
|
transform-origin: center center;
|
||||||
backgroundImage.style.zIndex = '-1';
|
`;
|
||||||
backgroundImage.style.filter = `blur(${settings.backgroundBlur}px) brightness(${settings.backgroundBrightness / 100}) contrast(${settings.backgroundContrast}%)`;
|
nowPlayingBackgroundContainer.appendChild(nowPlayingBackgroundImage);
|
||||||
backgroundImage.style.willChange = 'transform, filter';
|
|
||||||
backgroundImage.style.transformOrigin = 'center center';
|
// Create gradient overlay
|
||||||
|
nowPlayingGradientOverlay = document.createElement('div');
|
||||||
// Apply animation based on performance mode
|
nowPlayingGradientOverlay.className = 'now-playing-gradient-overlay';
|
||||||
if (settings.performanceMode) {
|
nowPlayingGradientOverlay.style.cssText = `
|
||||||
backgroundImage.style.animation = 'none';
|
position: absolute;
|
||||||
backgroundImage.classList.add('performance-mode-static');
|
left: 0;
|
||||||
} else {
|
top: 0;
|
||||||
backgroundImage.style.animation = `spin ${settings.spinSpeed}s linear infinite`;
|
width: 100%;
|
||||||
backgroundImage.classList.remove('performance-mode-static');
|
height: 100%;
|
||||||
|
background: radial-gradient(circle at center, transparent 0%, rgba(0, 0, 0, 0.3) 60%, rgba(0, 0, 0, 0.8) 90%);
|
||||||
|
z-index: -1;
|
||||||
|
pointer-events: none;
|
||||||
|
`;
|
||||||
|
nowPlayingBackgroundContainer.appendChild(nowPlayingGradientOverlay);
|
||||||
}
|
}
|
||||||
nowPlayingContainerElement.appendChild(backgroundImage);
|
|
||||||
|
|
||||||
// Create subtle gradient overlay to hide edges (Hate this approach but it's the only way I could get it to work)
|
// Update image source efficiently with caching
|
||||||
const gradientOverlay = document.createElement('div');
|
if (nowPlayingBackgroundImage && nowPlayingBackgroundImage.src !== coverArtImageSrc) {
|
||||||
gradientOverlay.className = 'now-playing-gradient-overlay';
|
// Check cache first
|
||||||
gradientOverlay.style.position = 'absolute';
|
if (imageCache.has(coverArtImageSrc)) {
|
||||||
gradientOverlay.style.left = '0';
|
nowPlayingBackgroundImage.src = coverArtImageSrc;
|
||||||
gradientOverlay.style.top = '0';
|
currentNowPlayingCoverSrc = coverArtImageSrc;
|
||||||
gradientOverlay.style.width = '100%';
|
} else {
|
||||||
gradientOverlay.style.height = '100%';
|
// Preload and cache the new image
|
||||||
gradientOverlay.style.background = 'radial-gradient(circle at center, transparent 0%, rgba(0, 0, 0, 0.3) 60%, rgba(0, 0, 0, 0.8) 90%)';
|
const preloadImg = new Image();
|
||||||
gradientOverlay.style.zIndex = '-1';
|
preloadImg.onload = () => {
|
||||||
gradientOverlay.style.pointerEvents = 'none';
|
// Add to cache (with size limit)
|
||||||
nowPlayingContainerElement.appendChild(gradientOverlay);
|
if (imageCache.size >= MAX_CACHE_SIZE) {
|
||||||
|
const firstKey = imageCache.keys().next().value;
|
||||||
|
if (firstKey) {
|
||||||
|
imageCache.delete(firstKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
imageCache.set(coverArtImageSrc, preloadImg);
|
||||||
|
|
||||||
|
if (nowPlayingBackgroundImage && nowPlayingBackgroundImage.src !== coverArtImageSrc) {
|
||||||
|
nowPlayingBackgroundImage.src = coverArtImageSrc;
|
||||||
|
currentNowPlayingCoverSrc = coverArtImageSrc;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
preloadImg.src = coverArtImageSrc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add keyframe animation if it doesn't exist
|
// Apply performance-optimized settings
|
||||||
if (!document.querySelector('#spinAnimation')) {
|
if (nowPlayingBackgroundImage) {
|
||||||
|
if (settings.performanceMode) {
|
||||||
|
// Ultra-light performance mode
|
||||||
|
nowPlayingBackgroundImage.style.width = '80vw';
|
||||||
|
nowPlayingBackgroundImage.style.height = '80vh';
|
||||||
|
const blur = Math.min(settings.backgroundBlur, 20);
|
||||||
|
const contrast = Math.min(settings.backgroundContrast, 150);
|
||||||
|
nowPlayingBackgroundImage.style.filter = `blur(${blur}px) brightness(${settings.backgroundBrightness / 100}) contrast(${contrast}%)`;
|
||||||
|
nowPlayingBackgroundImage.style.animation = 'none';
|
||||||
|
nowPlayingBackgroundImage.style.transform = 'translate(-50%, -50%)';
|
||||||
|
nowPlayingBackgroundImage.classList.add('performance-mode-static');
|
||||||
|
nowPlayingBackgroundImage.style.willChange = 'auto';
|
||||||
|
} else {
|
||||||
|
// OPTIMIZED Normal mode - Better performance while maintaining quality
|
||||||
|
nowPlayingBackgroundImage.style.width = '90vw';
|
||||||
|
nowPlayingBackgroundImage.style.height = '90vh';
|
||||||
|
// Use CSS custom properties for efficient dynamic updates
|
||||||
|
nowPlayingBackgroundImage.style.setProperty('--bg-contrast', `${settings.backgroundContrast}%`);
|
||||||
|
nowPlayingBackgroundImage.style.setProperty('--bg-brightness', `${settings.backgroundBrightness / 100}`);
|
||||||
|
nowPlayingBackgroundImage.style.setProperty('--bg-blur', `${settings.backgroundBlur}px`);
|
||||||
|
nowPlayingBackgroundImage.style.animation = `spin ${settings.spinSpeed}s linear infinite`;
|
||||||
|
nowPlayingBackgroundImage.classList.remove('performance-mode-static');
|
||||||
|
// Enhanced GPU acceleration for smoother animations
|
||||||
|
nowPlayingBackgroundImage.style.willChange = 'transform';
|
||||||
|
nowPlayingBackgroundImage.style.transformOrigin = 'center center';
|
||||||
|
// Force hardware acceleration with transform3d
|
||||||
|
nowPlayingBackgroundImage.style.transform = 'translate3d(-50%, -50%, 0)';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add keyframe animation only once
|
||||||
|
if (!spinAnimationAdded) {
|
||||||
const styleSheet = document.createElement('style');
|
const styleSheet = document.createElement('style');
|
||||||
styleSheet.id = 'spinAnimation';
|
styleSheet.id = 'spinAnimation';
|
||||||
styleSheet.textContent = `
|
styleSheet.textContent = `
|
||||||
@@ -625,12 +826,24 @@ const updateCoverArtBackground = function (method: number = 0): void {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
document.head.appendChild(styleSheet);
|
document.head.appendChild(styleSheet);
|
||||||
|
spinAnimationAdded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const cleanUpDynamicArt = function (): void {
|
const cleanUpDynamicArt = function (): void {
|
||||||
|
// Clean up cached Now Playing elements
|
||||||
|
if (nowPlayingBackgroundContainer && nowPlayingBackgroundContainer.parentNode) {
|
||||||
|
nowPlayingBackgroundContainer.parentNode.removeChild(nowPlayingBackgroundContainer);
|
||||||
|
}
|
||||||
|
nowPlayingBackgroundContainer = null;
|
||||||
|
nowPlayingBackgroundImage = null;
|
||||||
|
nowPlayingBlackBg = null;
|
||||||
|
nowPlayingGradientOverlay = null;
|
||||||
|
currentNowPlayingCoverSrc = null;
|
||||||
|
|
||||||
|
// Clean up any remaining elements (fallback)
|
||||||
const nowPlayingBackgroundImages = document.getElementsByClassName("now-playing-background-image");
|
const nowPlayingBackgroundImages = document.getElementsByClassName("now-playing-background-image");
|
||||||
Array.from(nowPlayingBackgroundImages).forEach((element) => {
|
Array.from(nowPlayingBackgroundImages).forEach((element) => {
|
||||||
element.remove();
|
element.remove();
|
||||||
@@ -644,6 +857,12 @@ const cleanUpDynamicArt = function (): void {
|
|||||||
observeForButtons();
|
observeForButtons();
|
||||||
observeTrackChanges();
|
observeTrackChanges();
|
||||||
observeLyricsContainer();
|
observeLyricsContainer();
|
||||||
|
|
||||||
|
// Apply initial performance mode class
|
||||||
|
if (settings.performanceMode) {
|
||||||
|
document.body.classList.add('performance-mode');
|
||||||
|
}
|
||||||
|
|
||||||
updateCoverArtBackground(1);
|
updateCoverArtBackground(1);
|
||||||
|
|
||||||
// Add cleanup to unloads
|
// Add cleanup to unloads
|
||||||
@@ -675,4 +894,7 @@ unloads.add(() => {
|
|||||||
|
|
||||||
// Clean up global spinning backgrounds
|
// Clean up global spinning backgrounds
|
||||||
cleanUpGlobalSpinningBackground();
|
cleanUpGlobalSpinningBackground();
|
||||||
|
|
||||||
|
// Clear image cache
|
||||||
|
imageCache.clear();
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user