mirror of
https://github.com/GuerillaStudio/now-playing
synced 2024-11-17 01:11:52 +00:00
25 lines
491 B
JavaScript
25 lines
491 B
JavaScript
class GoRandomAlbum {
|
|
constructor () {
|
|
this.urls = window.albumsUrls
|
|
this.btn = document.querySelector('[data-random="btn"]')
|
|
}
|
|
|
|
init () {
|
|
this.bindEvents()
|
|
}
|
|
|
|
bindEvents () {
|
|
if (this.btn && this.urls) {
|
|
this.btn.addEventListener('click', () => {
|
|
this.getRandomUrl()
|
|
})
|
|
}
|
|
}
|
|
|
|
getRandomUrl() {
|
|
const index = Math.floor(Math.random()*(this.urls.length+1));
|
|
window.location.href = this.urls[index]
|
|
}
|
|
}
|
|
|
|
new GoRandomAlbum().init()
|