Skip to content

Commit ec14e12

Browse files
authored
Merge pull request #4 from Lurking987/Lurking987-tmdb-backdrop-update-1
add transition effect to the background image
2 parents ab25375 + 83b0766 commit ec14e12

3 files changed

Lines changed: 44 additions & 33 deletions

File tree

plugins/tmdb-backdrop/manifest

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ id: tmdb-backdrop
22
name: TMDB Backdrops
33
metadata:
44
description: Check for TMDB URL, grab a backdrop, and display backdrop as background image
5-
version: 0.1
6-
date: "2026-02-11 00:00:00"
5+
version: 0.2
6+
date: "2026-02-25 00:00:00"
77
requires: []
88
source_repository: https://lurking987.github.io/stash-plugins/main/index.yml
99
files:

plugins/tmdb-backdrop/tmdb-backdrop.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: tmdb-backdrop
22
description: Check for TMDB URL and display random backdrop as background image
3-
version: 0.1
3+
version: 0.2
44
ui:
55
javascript:
66
- tmdb_ui.js
@@ -11,3 +11,4 @@ settings:
1111
tmdbapikey:
1212
displayName: TMDB API Key
1313
type: STRING
14+

plugins/tmdb-backdrop/tmdb_ui.js

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
const updateBackdrop = async (tmdbUrl) => {
2525
if (!apiKey) await getSettings();
26-
if (!apiKey) return console.error("TMDB Plugin: No API Key found in settings.");
26+
if (!apiKey) return;
2727

2828
const idMatch = tmdbUrl.match(/(movie|tv|collection)\/(\d+)/);
2929
if (!idMatch) return;
@@ -33,51 +33,61 @@
3333
const response = await fetch(`https://api.themoviedb.org/3/${type}/${tmdbId}/images?api_key=${apiKey}`);
3434
const data = await response.json();
3535

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}`;
4038

39+
// 1. Get or Create the style block
4140
let styleBlock = document.getElementById('tmdb-dynamic-style');
4241
if (!styleBlock) {
4342
styleBlock = document.createElement('style');
4443
styleBlock.id = 'tmdb-dynamic-style';
4544
document.head.appendChild(styleBlock);
4645
}
4746

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;
5659
}
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;
5978
}
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 {
6281
background-color: transparent !important;
63-
border-bottom: none !important; /* Optional: removes the bottom border line */
82+
box-shadow: none !important;
6483
}
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; }
7585
`;
76-
console.log("TMDB Plugin: Backdrop applied:", imageUrl);
7786
}
78-
} catch (e) { console.error("TMDB Plugin API Error:", e); }
87+
} catch (e) { console.error("TMDB Plugin Error:", e); }
7988
};
8089

90+
8191
async function updateDOM() {
8292
const match = window.location.pathname.match(/\/groups\/(\d+)/);
8393
if (!match) return;

0 commit comments

Comments
 (0)