notifications - Chrome, recognize open tab -


i'm creating extenstion google chrome perform checking if stream on twitch.tv online , notify user evey x minutes, got covered. i'm looking jscirpt code recognize if user on streamers channel , stop notifying him.

var username="$user";  setinterval(check,300000);  function check() {     request("https://api.twitch.tv/kraken/streams/" + username, function() {         var json = json.parse(this.response);         if (json.stream == null)         {             chrome.browseraction.seticon({ path: "offline.png" });         }         else         {             notify();         }     });     return 1; }  function notify(){     var opt = {type: "basic",title: username + " streaming!",message: "click join!",iconurl: "start.png"};         chrome.notifications.create("", opt, function(notificationid)              {                settimeout(function()                   {                     chrome.notifications.clear(notificationid, function(wascleared) { console.log(wascleared); });                   }, 3000);              });  chrome.browseraction.seticon({path:"online.png" }); }  chrome.browseraction.onclicked.addlistener(function () {     chrome.tabs.create({ url: "http://www.twitch.tv/"+username }); });  function request(url, func, post) {     var xhr = new xmlhttprequest();     xhr.onload = func;     xhr.open(post == undefined ? 'get' : 'post', url, true);     xhr.send(post || '');     return 1; }  check(); 

  • use window.location.href complete url.
  • use window.location.pathname url leaving host.

you can read more here.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -