@@ -16,35 +16,42 @@ async function initMusic() {
1616 t = document . getElementById ( "music" ) ,
1717 s = document . getElementById ( "music-skip" ) ,
1818 n = document . getElementById ( "music-info" ) ;
19- async function o ( ) {
19+ const playImg = t . querySelector ( ".music-icon.play" ) ;
20+ async function o ( ) {
2021 let newIndex ;
2122 do {
2223 newIndex = Math . floor ( Math . random ( ) * songs . length ) ;
2324 } while ( newIndex === currentSong && songs . length > 1 ) ;
24- currentSong = newIndex ;
25- e . src = `${ baseUrl } ${ songs [ currentSong ] . src } ` ;
26- e . play ( ) ;
27- t . setAttribute ( "title" , "Unpause the current song." ) ;
28- t . classList . add ( "paused" ) ;
29- s . style . display = "block" ;
30- n . textContent = songs [ currentSong ] . title ;
31- n . setAttribute ( "title" , songs [ currentSong ] . title ) ;
32- }
33- currentSong = Math . floor ( Math . random ( ) * songs . length ) ;
25+ currentSong = newIndex ;
3426 e . src = `${ baseUrl } ${ songs [ currentSong ] . src } ` ;
27+ e . play ( ) ;
28+ t . setAttribute ( "title" , "Pause the current song." ) ;
29+ t . classList . add ( "paused" ) ;
30+ if ( playImg ) playImg . src = "/img/music/pause.png" ;
31+ s . style . display = "block" ;
32+ n . textContent = songs [ currentSong ] . title ;
3533 n . setAttribute ( "title" , songs [ currentSong ] . title ) ;
36- t . addEventListener ( "click" , async function ( ) {
34+ }
35+ currentSong = Math . floor ( Math . random ( ) * songs . length ) ;
36+ e . src = `${ baseUrl } ${ songs [ currentSong ] . src } ` ;
37+ n . setAttribute ( "title" , songs [ currentSong ] . title ) ;
38+ if ( playImg ) playImg . src = "/img/music/play.png" ;
39+ t . setAttribute ( "title" , "Unpause the current song." ) ;
40+ t . classList . remove ( "paused" ) ;
41+ t . addEventListener ( "click" , async function ( ) {
3742 if ( e . paused ) {
38- e . play ( ) ;
43+ await e . play ( ) ;
3944 t . classList . add ( "paused" ) ;
40- t . setAttribute ( "title" , "Pause the current song." )
45+ t . setAttribute ( "title" , "Pause the current song." ) ;
46+ if ( playImg ) playImg . src = "/img/music/pause.png" ;
4147 s . style . display = "block" ;
4248 n . textContent = songs [ currentSong ] . title ;
4349 n . setAttribute ( "title" , songs [ currentSong ] . title ) ;
4450 } else {
4551 e . pause ( ) ;
4652 t . classList . remove ( "paused" ) ;
4753 t . setAttribute ( "title" , "Unpause the current song." ) ;
54+ if ( playImg ) playImg . src = "/img/music/play.png" ;
4855 }
4956 } ) ;
5057 s . addEventListener ( "click" , o ) ;
0 commit comments