Hello,
I’m trying to adapt a browser extension that shows whether the streamer is online or not.
I can not adapt the code to the new API
Do you have any leads?
app.js :
var xhr = new XMLHttpRequest()
xhr.open("GET", "https://api.twitch.tv/kraken/streams/platiscript?client_id=XXXXXXXX", true)
xhr.onreadystatechange = function(channel) {
if(xhr.readyState == 4) {
var data = JSON.parse(xhr.responseText)
var elm = document.getElementById("info")
if(data["stream"] === null){
elm.style.color = "red"
elm.innerHTML = "La SubData TV n'est pas en live actuellement :("
}else{
elm.style.color = "green"
elm.innerHTML = "Viens voir SubData en live maintenant !"
}
}
}
xhr.send()
background.js :
function checkStream() {
var xhr = new XMLHttpRequest()
xhr.open("GET", "https://api.twitch.tv/kraken/streams/LeFresechReream?client_id=XXXXX", true)
xhr.onreadystatechange = function () {
if(xhr.readyState == 4) {
var data = JSON.parse(xhr.responseText)
if(data["stream"] === null){
chrome.browserAction.setIcon({path:"img/icon_red.png"})
}else{
chrome.browserAction.setIcon({path:"img/icon_green.png"})
}
// On relance la fonction après X secondes
setTimeout(checkStream, tickRate)
}
}
xhr.send()
}
Thank