var debug = JSON.parse(localStorage.channel);
var liveNotify = new Notification('ADANADO!!', {
      icon: 'icon128.png',
      body: "É TEMPO! Começando "+debug.game+" ao vivo agora!",
      silent: true
    });

liveNotify.onclick = function(){
    chrome.tabs.create({'url': 'http://www.twitch.tv/cogumelandooficial/'}, function(tab){/*callback*/}); 
};
setTimeout(function(){
    liveNotify.close();
},10000); 

var twitch = {
    name: 'Cogumelando',
    username: 'cogumelandooficial',
    streamTitle: 'LIVE',
    offAirTitle: 'OFF',
    offAirMessage: 'Off-air'
}

chrome.runtime.onStartup.addListener(function () {
    localStorage.removeItem('onStream');
    if(localStorage.length == 0){
        localStorage.setItem('persist',true);
        localStorage.setItem('sound',true);
        localStorage.setItem('interval',1);
    }
    noConnect();
    chrome.alarms.create("mainLoop", {delayInMinutes: 0.1,periodInMinutes: 1});
});
$.ajaxSetup({cache:false});

/*@deprecated
twitch.createLoop();
getTwitch(twitch.username);
twitch.mainLoop = setInterval(function(){
    getTwitch(twitch.username);
},twitch.ajaxInterval);
*/

chrome.alarms.onAlarm.addListener(function(alarm) {
    getTwitch(twitch.username);
});

function mythTwitch(twitchJson){
    twitch.channel = twitchJson;

    if(twitchJson.stream){
        localStorage.setItem('onStream',true);
        localStorage.setItem('channel',JSON.stringify(twitchJson.stream));
        
        chrome.browserAction.getBadgeText({},function(e){
            console.log(e);
            if(e != twitch.streamTitle && localStorage.sound){
                var notify = new Howl({
                    urls: ['adanado.ogg']
                }).play();
            }
        });
        
        twitch.game = twitchJson.stream.game;
        chrome.browserAction.setBadgeBackgroundColor({color: "#0d0"});
        chrome.browserAction.setBadgeText({text:twitch.streamTitle});
        chrome.browserAction.setTitle({title:twitch.name+' | '+twitch.game});

        console.log("Stream");

    }else{
        localStorage.removeItem('onStream');
        chrome.browserAction.setBadgeBackgroundColor({color: "#d00"});
        chrome.browserAction.setBadgeText({text:twitch.offAirTitle});
        chrome.browserAction.setTitle({title:twitch.name+' | '+twitch.offAirMessage});
        console.log("Off-air");
    }
}

function getTwitch(username){
    $.ajax({
        url:'https://api.twitch.tv/kraken/streams/'+username,
        success:function(channel) {
            console.log('Objeto recebido');
            mythTwitch(channel);
        },
        error:function() {
            console.log('Sem conexão');
            noConnect();
        }
    });
}

function noConnect(){
    chrome.browserAction.setBadgeText({text:"..."});
    chrome.browserAction.setBadgeBackgroundColor({color: "#999"});
    chrome.browserAction.setTitle({title:twitch.name});
}

@@ -1,419 +1,4 @@
-var debug = JSON.parse(localStorage.channel);%0Avar liveNotify = new Notification('ADANADO!!', %7B%0A      icon: 'icon128.png',%0A      body: %22%C3%89 TEMPO! Come%C3%A7ando %22+debug.game+%22 ao vivo agora!%22,%0A      silent: true%0A    %7D);%0A%0AliveNotify.onclick = function()%7B%0A    chrome.tabs.create(%7B'url': 'http://www.twitch.tv/cogumelandooficial/'%7D, function(tab)%7B/*callback*/%7D); %0A%7D;%0AsetTimeout(function()%7B%0A    liveNotify.close();%0A%7D,10000); %0A
 %0Avar
@@ -147,16 +147,46 @@
 Off-air'
+,%0A    notifySfx: 'adanado.ogg'
 %0A%7D%0A%0Achro
@@ -229,17 +229,16 @@
 ction ()
- 
 %7B%0A    lo
@@ -388,32 +388,77 @@
 ('sound',true);%0A
+        localStorage.setItem('notify',true);%0A
         localSto
@@ -1091,32 +1091,70 @@
 ream));%0A        
+twitch.game = twitchJson.stream.game;%0A
 %0A        chrome.
@@ -1266,33 +1266,56 @@
 itle
- && localStorage.sound)%7B%0A
+)%7B%0A                if(localStorage.notify)%7B%0A    
     
@@ -1330,17 +1330,21 @@
     var 
-n
+liveN
 otify = 
@@ -1351,13 +1351,34 @@
 new 
-Howl(
+Notification('ADANADO!!', 
 %7B%0A  
@@ -1399,91 +1399,517 @@
     
+ 
-urls: %5B'ad
+     icon: 'live.png',%0A                          body: %22%C3%89 TEMPO! Come%C3%A7
 an
-a
 do
-.ogg'%5D%0A                %7D).play();%0A            %7D%0A        %7D);%0A
+ %22+twitch.game+%22 ao vivo agora!%22,%0A                          silent: true%0A                        %7D);%0A%0A                    liveNotify.onclick = function()%7B%0A                        chrome.tabs.create(%7B'url': 'http://www.twitch.tv/cogumelandooficial/'%7D, function(tab)%7B/*callback*/%7D);%0A                    %7D;%0A                    setTimeout(function()%7B%0A                        liveNotify.close();%0A                    %7D,10000);%0A     
         
 %0A   
@@ -1904,25 +1904,30 @@
         
-%0A
+   %7D%0A 
         
 twitch.g
@@ -1922,45 +1922,209 @@
     
-twitch.game = twitchJson.stream.game;
+       if (localStorage.sound) %7B%0A                    var notify = new Howl(%7B%0A                        urls: %5Btwitch.notifySfx%5D%0A                    %7D).play();%0A                %7D%0A            %7D%0A        %7D);%0A
 %0A   

Add desktop notify - testado e incrementado no loop principal - falta colocar nas configurações