function search(searchfield) { txt = searchfield.value; if (txt == "") { reallyclear() } else { xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = searchresult xhttp.open("GET","/api/search?max=5&query=" + encodeURIComponent(txt), true); xhttp.send(); } } function searchresult() { if (this.readyState == 4 && this.status == 200 && document.getElementById("searchinput").value != "") { // checking if field is empty in case we get an old result coming in that would overwrite our cleared result window result = JSON.parse(this.responseText); artists = result["artists"].slice(0,5) tracks = result["tracks"].slice(0,5) html = `
Artists ` for (var i=0;i ` } html += `
` + name + `


Tracks ` for (var i=0;i "artist=" + encodeURIComponent(x)).join("&"); uristr = uristr.replace("'","\\'"); image = "/image?" + uristr; link = "/track?" + uristr; html += `` } html += `
` + artists + `
` + title + `
` document.getElementById("resultwrap").innerHTML = html; } } function clearresults() { window.setTimeout(reallyclear,500) } function reallyclear() { document.getElementById("resultwrap").innerHTML = ""; } function goto(link) { window.location = link }