From bca4c7f22636ddcaf952126e57827725a2914367 Mon Sep 17 00:00:00 2001 From: Alan Raju <37742577+CipherKill@users.noreply.github.com> Date: Wed, 21 Sep 2022 13:35:49 +0530 Subject: [PATCH] feat: add stop music button to stop playing song at anytime * Added the pause button(visual only) * Renamed pause to stop * Added enablejsapi parameter to the youtube links * Added stop button feature (visual and function) * Finishing touches for the stop music feature * Extended stop button feature to individual songs --- index.html | 7 ++++++- index.js | 26 ++++++++++++++++++++++++-- styles.css | 19 +++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 0e20e6ba..62aef71b 100644 --- a/index.html +++ b/index.html @@ -63,7 +63,12 @@

A very Mogul Christmas

-
+ + +
+ +
+ diff --git a/index.js b/index.js index c609b645..151b6157 100644 --- a/index.js +++ b/index.js @@ -33,8 +33,11 @@ const embed = document.getElementById("embed"); const newTabGithub = document.querySelector(".social"); const toggle = document.querySelector(".round"); const slider = document.querySelector(".slider"); + + toggle.addEventListener("click", modeSwitch); + // Darkmode/Lightmode + Making songs play when clicked let isLight = true; @@ -58,11 +61,15 @@ Object.keys(songs).map((song_title) => { const startTime = songs[song_title].start; const endTime = songs[song_title].end; const outerElem = document.createElement("p"); + + //stop button for individual songs + outerElem.onclick=()=>revealStopButton(); + const link = document.createElement("a"); link.innerHTML = song_title; link.style = "cursor: pointer"; link.onclick = () => { - embed.src = `https://www.youtube.com/embed/TtY9eRayseg?start=${startTime}&autoplay=1&end=${endTime}`; + embed.src = `https://www.youtube.com/embed/TtY9eRayseg?start=${startTime}&autoplay=1&end=${endTime}&enablejsapi=1`; console.log( "If you don't know this song, we suggest you go to the lyrics page. You can play the song from that page too :)" ); @@ -76,12 +83,13 @@ Object.keys(songs).map((song_title) => { // randomly shuffle a song from main page's songs function shuffleSongs() { + revealStopButton(); var properties = Object.getOwnPropertyNames(songs); var ranNum = Math.floor(Math.random() * (properties.length - 1)); var songName = properties[ranNum]; var song = songs[songName]; console.log(songs[songName]); - embed.src = `https://www.youtube.com/embed/TtY9eRayseg?start=${song.start}&autoplay=1&end=${song.end}`; + embed.src = `https://www.youtube.com/embed/TtY9eRayseg?start=${song.start}&autoplay=1&end=${song.end}&enablejsapi=1`; } // Open GitHub repo in a new window if user clicks GitHub icon on project website @@ -92,3 +100,17 @@ newTabGithub.addEventListener("click", () => { "resizable=yes, scroll=yes, location=1, titlebar=yes, width=800, height=900, top=10, left=10" ); }); + +//stop-button-feature +const stopButton=document.querySelector("#stop-btn"); //stop button + +//make the stop button visible when "play random song button is clicked" +function revealStopButton(){ + stopButton.style.display='block'; +} + +//stop button function +function stopVideo(){ + embed.contentWindow.postMessage('{"event":"command","func":"stopVideo","args":""}','*'); + stopButton.style.display='none'; +} \ No newline at end of file diff --git a/styles.css b/styles.css index 9af663ce..48c8e7b9 100644 --- a/styles.css +++ b/styles.css @@ -197,6 +197,25 @@ a:active { margin-top: 1rem; } +.stop-btn-style{ + display:none; + background-image: radial-gradient( + circle farthest-corner at 92.3% 71.5%, + rgb(255, 85, 0) 0%, + rgb(173, 0, 0) 90% + ); + color: white; + outline: none; + border: none; + font-family: "Handlee", cursive; + font-size: 1.5rem; + cursor: pointer; + padding: 0.5rem 1rem; + border-radius: 5px; + transition: all 0.2s ease-in-out; + margin-top: 1rem; +} + .suggest { background-color: #f4d03f; background-image: linear-gradient(132deg, #f4d03f 0%, #16a085 100%);