Skip to content

Commit

Permalink
feat: display full screen
Browse files Browse the repository at this point in the history
  • Loading branch information
san1234100 committed Feb 27, 2024
1 parent 0477bed commit 861ee5c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
34 changes: 33 additions & 1 deletion assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function getThumbnail() {
if (videoId) {
let thumbnailUrl = 'https://img.youtube.com/vi/' + videoId + '/maxresdefault.jpg';
console.log(thumbnailUrl);
youtubeThumbnailEl.innerHTML = '<img src="' + thumbnailUrl + '">';
youtubeThumbnailEl.innerHTML = '<img class="w-[100%]" src="' + thumbnailUrl + '">';
} else {
alert('Invalid YouTube Link');
}
Expand All @@ -25,4 +25,36 @@ function getThumbnail() {
} else {
return null;
}
}

youtubeThumbnailEl.addEventListener('click', () => {
if (document.youtubeThumbnailEl) {
exitFullscreen();
} else {
enterFullscreen(youtubeThumbnailEl);
}
});

function enterFullscreen(element) {
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.mozRequestFullScreen) { /* Firefox */
element.mozRequestFullScreen();
} else if (element.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
element.webkitRequestFullscreen();
} else if (element.msRequestFullscreen) { /* IE/Edge */
element.msRequestFullscreen();
}
}

function exitFullscreen() {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) { /* Firefox */
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) { /* Chrome, Safari and Opera */
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) { /* IE/Edge */
document.msExitFullscreen();
}
}
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h1 class="text-2xl font-semibold">YoutubeThumbGrab</h1>
<button class="w-full mt-3 py-2 bg-[#720455] rounded font-medium hover:bg-[#61084a]">Grab the thumbnail</button>
<div class="mt-5 rounded" id="youtubeThumbnail"></div>
</div>

<div class="text-center text-white font-semibold text-2xl mt-5">Click on image to display full screen</div>
<script type="module" src="/assets/js/main.js"></script>
</body>
</html>

0 comments on commit 861ee5c

Please sign in to comment.