使用XML数据和Javascript制作在线/离线Livestream徽章

使用XML数据和Javascript制作在线/离线Livestream徽章,javascript,live,badge,Javascript,Live,Badge,我正在尝试制作一个徽章,上面写着我的Livestream频道是在线还是离线。我发现一些javascript可以为Twitch频道实现这一点: (function() { var user_name, twitch_widget; user_name = "nerdist"; twitch_widget = $("#twitch-widget"); twitch_widget.attr("href","http://twitch.tv/" + user_name + "/em

我正在尝试制作一个徽章,上面写着我的Livestream频道是在线还是离线。我发现一些javascript可以为Twitch频道实现这一点:

(function() {

  var user_name, twitch_widget;

  user_name = "nerdist";
  twitch_widget = $("#twitch-widget");

  twitch_widget.attr("href","http://twitch.tv/" + user_name + "/embed");

  $.getJSON('https://api.twitch.tv/kraken/streams/' + user_name + '?client_id=' + '&callback=?', function(data) {   
      if (data.stream) {
          twitch_widget.html("<span class='online'></span><strong> nerdist</strong></br><span class='live'>Online! Playing: " + data.stream.game + "</span>");
      } else {
          twitch_widget.html("<span class='offline'></span><strong> nerdist</strong></br><span class='notlive'>Offline</span>");
      }  
  });

})();
但是我不知道应该放什么来代替“函数(数据)”和“如果(数据流)”。比如“如果(isLive=true)”可能

任何帮助都将不胜感激。

(函数(){
(function() {

  var livestream_widget;

  livestream_widget = $("#livestream-widget");

  livestream_widget.attr("href","[channelurl]");
  $.getJSON('http://xdaytradingradiox.api.channel.livestream.com/2.0/livestatus.json?callback=?', function(data) {  

      if (data.channel.isLive === true) {

          livestream_widget.html("<span class='online'></span><strong> daytradingradio</strong></br><span class='live'>Online!</span>");
      } else {
          livestream_widget.html("<span class='offline'></span><strong> daytradingradio</strong></br><span class='notlive'>Offline</span>");
      }  
  });

})();
var-livestream_小部件; livestream_widget=$(“#livestream widget”); livestream_widget.attr(“href”,“[channelurl]”); $.getJSON('http://xdaytradingradiox.api.channel.livestream.com/2.0/livestatus.json?callback=?,函数(数据){ if(data.channel.isLive==true){ livestream_widget.html(“daytradingradio
在线!”); }否则{ livestream_widget.html(“daytradingradio
离线”); } }); })();
查看此页面:我可以看到可以使用JSON而不是XML。不确定这是否会更好。同样,这个线程看起来非常相似,但我仍然不确定如何在我使用的代码中实现它:
(function() {

  var livestream_widget;

  livestream_widget = $("#livestream-widget");

  livestream_widget.attr("href","[channelurl]");
  $.getJSON('http://xdaytradingradiox.api.channel.livestream.com/2.0/livestatus.json?callback=?', function(data) {  

      if (data.channel.isLive === true) {

          livestream_widget.html("<span class='online'></span><strong> daytradingradio</strong></br><span class='live'>Online!</span>");
      } else {
          livestream_widget.html("<span class='offline'></span><strong> daytradingradio</strong></br><span class='notlive'>Offline</span>");
      }  
  });

})();