|
23 | 23 |
|
24 | 24 | const updateBackdrop = async (tmdbUrl) => { |
25 | 25 | if (!apiKey) await getSettings(); |
26 | | - if (!apiKey) return console.error("TMDB Plugin: No API Key found in settings."); |
| 26 | + if (!apiKey) return; |
27 | 27 |
|
28 | 28 | const idMatch = tmdbUrl.match(/(movie|tv|collection)\/(\d+)/); |
29 | 29 | if (!idMatch) return; |
|
33 | 33 | const response = await fetch(`https://api.themoviedb.org/3/${type}/${tmdbId}/images?api_key=${apiKey}`); |
34 | 34 | const data = await response.json(); |
35 | 35 |
|
36 | | - if (data.backdrops && data.backdrops.length > 0) { |
37 | | - const randomIdx = Math.floor(Math.random() * data.backdrops.length); |
38 | | - const filePath = data.backdrops[randomIdx].file_path; |
39 | | - const imageUrl = `https://image.tmdb.org/t/p/original${filePath}`; |
| 36 | + if (data.backdrops?.length > 0) { |
| 37 | + const imageUrl = `https://image.tmdb.org/t/p/original${data.backdrops[Math.floor(Math.random() * data.backdrops.length)].file_path}`; |
40 | 38 |
|
| 39 | + // 1. Get or Create the style block |
41 | 40 | let styleBlock = document.getElementById('tmdb-dynamic-style'); |
42 | 41 | if (!styleBlock) { |
43 | 42 | styleBlock = document.createElement('style'); |
44 | 43 | styleBlock.id = 'tmdb-dynamic-style'; |
45 | 44 | document.head.appendChild(styleBlock); |
46 | 45 | } |
47 | 46 |
|
48 | | - // Target #group-page for the image and .detail-header for transparency |
49 | | - styleBlock.innerHTML = ` |
50 | | - #group-page { |
51 | | - background-image: linear-gradient(rgba(0,0,0,0.6), rgba(0,0,0,0.6)), url("${imageUrl}") !important; |
52 | | - background-size: cover !important; |
53 | | - background-attachment: fixed !important; |
54 | | - background-position: center !important; |
55 | | - min-height: 100vh; |
| 47 | + // 2. Start Fade Out: Only the background layer |
| 48 | + const styleBase = ` |
| 49 | + #group-page { position: relative; min-height: 100vh; background: transparent !important; } |
| 50 | + #group-page::before { |
| 51 | + content: ""; |
| 52 | + position: fixed; |
| 53 | + top: 0; left: 0; width: 100%; height: 100%; |
| 54 | + z-index: -1; |
| 55 | + background-size: cover; |
| 56 | + background-attachment: fixed; |
| 57 | + background-position: center; |
| 58 | + transition: opacity 0.8s ease-in-out; |
56 | 59 | } |
57 | | - #group-page .background-image-container { |
58 | | - display: none !important; |
| 60 | + `; |
| 61 | + |
| 62 | + // Set opacity to 0 on the existing background layer |
| 63 | + const currentStyle = styleBlock.innerHTML; |
| 64 | + styleBlock.innerHTML = styleBase + currentStyle + `#group-page::before { opacity: 0 !important; }`; |
| 65 | + |
| 66 | + // 3. Preload and Wait for fade out |
| 67 | + await Promise.all([ |
| 68 | + new Promise(resolve => setTimeout(resolve, 800)), |
| 69 | + new Promise(resolve => { const img = new Image(); img.src = imageUrl; img.onload = resolve; }) |
| 70 | + ]); |
| 71 | + |
| 72 | + // 4. Update image and Fade In |
| 73 | + styleBlock.innerHTML = ` |
| 74 | + ${styleBase} |
| 75 | + #group-page::before { |
| 76 | + background-image: linear-gradient(rgba(0,0,0,0.6), rgba(0,0,0,0.6)), url("${imageUrl}"); |
| 77 | + opacity: 1 !important; |
59 | 78 | } |
60 | | - /* Clear the header background to reveal the TMDB image */ |
61 | | - #group-page .detail-header { |
| 79 | + #group-page .background-image-container { display: none !important; } |
| 80 | + #group-page .detail-header, #group-page .filtered-list-toolbar, #group-page .card { |
62 | 81 | background-color: transparent !important; |
63 | | - border-bottom: none !important; /* Optional: removes the bottom border line */ |
| 82 | + box-shadow: none !important; |
64 | 83 | } |
65 | | - #group-page .filtered-list-toolbar { |
66 | | - background-color: transparent !important; |
67 | | - } |
68 | | - #group-page .card { |
69 | | - background-color: transparent !important; |
70 | | - box-shadow: none !important; |
71 | | - } |
72 | | - #group-page .detail-body nav { |
73 | | - border-bottom: solid 0px; |
74 | | - } |
| 84 | + #group-page .detail-body nav { border-bottom: none !important; } |
75 | 85 | `; |
76 | | - console.log("TMDB Plugin: Backdrop applied:", imageUrl); |
77 | 86 | } |
78 | | - } catch (e) { console.error("TMDB Plugin API Error:", e); } |
| 87 | + } catch (e) { console.error("TMDB Plugin Error:", e); } |
79 | 88 | }; |
80 | 89 |
|
| 90 | + |
81 | 91 | async function updateDOM() { |
82 | 92 | const match = window.location.pathname.match(/\/groups\/(\d+)/); |
83 | 93 | if (!match) return; |
|
0 commit comments