feat: mock when running locally
This commit is contained in:
parent
12f4929dd3
commit
6757a60134
22 changed files with 1342 additions and 300 deletions
|
@ -1,39 +1,41 @@
|
|||
;(async function () {
|
||||
const nowPlaying = document.getElementById('now-playing')
|
||||
if (window.location.hostname !== 'localhost') {
|
||||
;(async function () {
|
||||
const nowPlaying = document.getElementById('now-playing')
|
||||
|
||||
if (nowPlaying) {
|
||||
const content = document.getElementById('now-playing-content')
|
||||
const loading = document.getElementById('now-playing-loading')
|
||||
if (nowPlaying) {
|
||||
const content = document.getElementById('now-playing-content')
|
||||
const loading = document.getElementById('now-playing-loading')
|
||||
|
||||
const populateNowPlaying = (data) => {
|
||||
loading.style.display = 'none'
|
||||
content.innerHTML = data.content
|
||||
content.classList.remove('hidden')
|
||||
}
|
||||
|
||||
try {
|
||||
const cache = JSON.parse(localStorage.getItem('now-playing'))
|
||||
if (cache) populateNowPlaying(cache)
|
||||
} catch (e) {
|
||||
/* quiet catch */
|
||||
}
|
||||
|
||||
const data = await fetch('/api/now-playing', {
|
||||
type: 'json',
|
||||
})
|
||||
.then((data) => data.json())
|
||||
.catch(() => {
|
||||
const populateNowPlaying = (data) => {
|
||||
loading.style.display = 'none'
|
||||
content.innerHTML = data.content
|
||||
content.classList.remove('hidden')
|
||||
}
|
||||
|
||||
try {
|
||||
const cache = JSON.parse(localStorage.getItem('now-playing'))
|
||||
if (cache) populateNowPlaying(cache)
|
||||
} catch (e) {
|
||||
/* quiet catch */
|
||||
}
|
||||
|
||||
const data = await fetch('/api/now-playing', {
|
||||
type: 'json',
|
||||
})
|
||||
.then((data) => data.json())
|
||||
.catch(() => {
|
||||
loading.style.display = 'none'
|
||||
})
|
||||
|
||||
try {
|
||||
localStorage.setItem('now-playing', JSON.stringify(data))
|
||||
} catch (e) {
|
||||
/* quiet catch */
|
||||
try {
|
||||
localStorage.setItem('now-playing', JSON.stringify(data))
|
||||
} catch (e) {
|
||||
/* quiet catch */
|
||||
}
|
||||
|
||||
if (!JSON.parse(localStorage.getItem('now-playing')) && !data) nowPlaying.remove()
|
||||
|
||||
populateNowPlaying(data)
|
||||
}
|
||||
|
||||
if (!JSON.parse(localStorage.getItem('now-playing')) && !data) nowPlaying.remove()
|
||||
|
||||
populateNowPlaying(data)
|
||||
}
|
||||
})()
|
||||
})()
|
||||
}
|
||||
|
|
Reference in a new issue