Skip to content

Commit 7e30bbc

Browse files
committed
fixed video size issue
1 parent 3fe9178 commit 7e30bbc

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

docs/pomodoro-timer.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/pomodoro-timer.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ body {
278278

279279
.video-container {
280280
margin: 2rem 0;
281-
width: 100%;
282281
width: 1080px;
283282
height: 720px;
284283
}

src/pomodoro-timer.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,15 @@ class PomodoroTimer extends DataroomElement {
178178
}
179179

180180
loadRandomVideo(container) {
181+
this.loadVideoWithFallback(container, 0);
182+
}
183+
184+
loadVideoWithFallback(container, attemptCount) {
185+
if (attemptCount >= 5) {
186+
container.innerHTML = '<div class="video-placeholder">Unable to load video after multiple attempts</div>';
187+
return;
188+
}
189+
181190
const playlist = this.getRandomPlaylist();
182191
if (!playlist) {
183192
container.innerHTML = '<div class="video-placeholder">Loading relaxation video...</div>';
@@ -198,6 +207,32 @@ class PomodoroTimer extends DataroomElement {
198207
iframe.allow = 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture';
199208
iframe.allowFullscreen = true;
200209
iframe.className = 'youtube-player';
210+
211+
// Handle iframe load errors (age restrictions, unavailable videos)
212+
iframe.addEventListener('error', () => {
213+
console.log('Video failed to load, trying another...');
214+
this.loadVideoWithFallback(container, attemptCount + 1);
215+
});
216+
217+
// Check for age restriction after load
218+
iframe.addEventListener('load', () => {
219+
setTimeout(() => {
220+
try {
221+
// If iframe content is blocked or shows age restriction, try another video
222+
const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
223+
if (!iframeDoc || iframeDoc.title.includes('restricted') || iframeDoc.title.includes('unavailable')) {
224+
console.log('Video appears to be restricted, trying another...');
225+
this.loadVideoWithFallback(container, attemptCount + 1);
226+
return;
227+
}
228+
} catch (e) {
229+
// Cross-origin restrictions prevent access, assume video is working
230+
console.log('Video loaded successfully');
231+
}
232+
}, 2000);
233+
});
234+
235+
container.innerHTML = '';
201236
container.appendChild(iframe);
202237
}
203238

0 commit comments

Comments
 (0)