Skip to content

Commit

Permalink
🐛 fix: lyrics cinema background
Browse files Browse the repository at this point in the history
  • Loading branch information
sanoojes committed Sep 3, 2024
1 parent ae81b82 commit fd225ff
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 4 deletions.
5 changes: 4 additions & 1 deletion extension/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React from 'react';
import Main from '@/components/Main';
import { showError } from '@/components/error/ErrorBoundary';
import { checkForCustomControls } from '@/utils/windowControls';
import { logToConsole } from './utils/logUtils';
import { logToConsole } from '@/utils/logUtils';
import { manageBackgroundZIndex } from '@/utils/backgroundUtils';

async function main() {
try {
Expand Down Expand Up @@ -48,6 +49,8 @@ async function main() {
document.querySelector('.Root__globalNav')
);

manageBackgroundZIndex();

// check for custom controls
checkForCustomControls();

Expand Down
1 change: 1 addition & 0 deletions extension/src/components/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const Main = () => {
React.useEffect(() => {
window.pageCategory = pageCategory;
document.body.classList.add(pageCategory);

return () => {
document.body.classList.remove(pageCategory);
};
Expand Down
58 changes: 58 additions & 0 deletions extension/src/utils/backgroundUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
export const manageBackgroundZIndex = () => {
type BackgroundContainer = HTMLDivElement | null;

function applyBackgroundStyles() {
const lyricsCinemaContainer: BackgroundContainer = document.querySelector(
'#lyrics-cinema:has(.lyrics-lyrics-contentContainer)'
);

if (lyricsCinemaContainer) {
const backgroundContainer: BackgroundContainer = document.querySelector(
'#lucid-main .background-container .background-wrapper div'
);

if (backgroundContainer) {
backgroundContainer.style.zIndex =
'calc(var(--above-everything-except-now-playing-bar-z-index, 6) - 1)';
} else {
removeBackgroundZIndex();
}
} else {
removeBackgroundZIndex();
}
}

function removeBackgroundZIndex() {
const backgroundContainer: BackgroundContainer = document.querySelector(
'#lucid-main .background-container .background-wrapper div'
);

if (backgroundContainer) {
backgroundContainer.style.zIndex = '';
}
}

const observer = new MutationObserver((mutations) => {
for (const mutation of mutations) {
if (
mutation.target instanceof HTMLElement &&
mutation.target.id === 'lyrics-cinema'
) {
applyBackgroundStyles();
} else {
if (
mutation.target instanceof HTMLElement &&
mutation.target.classList.contains('lyrics-lyrics-contentContainer')
) {
applyBackgroundStyles();
}
}
}
});

const config = { childList: true, attributes: true, subtree: true };

observer.observe(document.body, config);

applyBackgroundStyles();
};
Loading

0 comments on commit fd225ff

Please sign in to comment.