Created
May 3, 2021 15:07
-
-
Save l3gacyb3ta/e326abc43f70279daf7d6ee8e13dced4 to your computer and use it in GitHub Desktop.
Just a js script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log("hi") | |
const app = document.getElementById('root') | |
const container = document.createElement('div') | |
container.setAttribute('class', 'container') | |
function req() { | |
app.appendChild(container) | |
var request = new XMLHttpRequest() | |
request.open('GET', 'https://spotapi.arbee.repl.co/', true) | |
request.onload = function () { | |
// Begin accessing JSON data here | |
var data = JSON.parse(this.response) | |
if (request.status >= 200 && request.status < 400) { | |
const spotify = document.createElement("div"); | |
console.log(spotify.setAttribute("class", "spotify")); | |
const song = document.createElement('img'); | |
song.src = data.image; | |
console.log(data); | |
const title = document.createElement('h1'); | |
title.innerHTML = data.title; | |
spotify.appendChild(song); | |
spotify.appendChild(title); | |
app.innerHTML = "" | |
app.appendChild(spotify); | |
} else { | |
const errorMessage = document.createElement('marquee') | |
errorMessage.textContent = `Gah, it's not working!` | |
app.appendChild(errorMessage) | |
} | |
} | |
request.send() | |
} | |
var intervalId = window.setInterval(function () { | |
req(); | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment