Skip to content

Instantly share code, notes, and snippets.

@l3gacyb3ta
Created May 3, 2021 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save l3gacyb3ta/e326abc43f70279daf7d6ee8e13dced4 to your computer and use it in GitHub Desktop.
Save l3gacyb3ta/e326abc43f70279daf7d6ee8e13dced4 to your computer and use it in GitHub Desktop.
Just a js script
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