1
0
Fork 0
mirror of https://github.com/GuerillaStudio/now-playing synced 2024-12-30 14:21:56 +00:00
now-playing/assets/js/random.js

26 lines
489 B
JavaScript
Raw Normal View History

2019-12-03 21:18:10 +00:00
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() {
2019-12-04 02:54:01 +00:00
const index = Math.floor(Math.random()*(this.urls.length));
2019-12-03 21:18:10 +00:00
window.location.href = this.urls[index]
}
}
new GoRandomAlbum().init()