Notifications Chrome,识别打开的选项卡

Notifications Chrome,识别打开的选项卡,notifications,twitch,Notifications,Twitch,我正在为google chrome创建一个扩展,该扩展将检查twitch.tv上的流是否在线,并每隔X分钟通知用户,我已经完成了。我要寻找的是一个JScirpt代码,它可以识别用户是否已经在拖缆通道上,并停止通知他 var username="$user"; setInterval(check,300000); function check() { request("https://api.twitch.tv/kraken/streams/" + username, function

我正在为google chrome创建一个扩展,该扩展将检查twitch.tv上的流是否在线,并每隔X分钟通知用户,我已经完成了。我要寻找的是一个JScirpt代码,它可以识别用户是否已经在拖缆通道上,并停止通知他

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 + " is streaming!",message: "Click to 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();
  • 使用window.location.href获取完整的URL
  • 使用window.location.pathname获取离开主机的URL
您可以阅读更多

  • 使用window.location.href获取完整的URL
  • 使用window.location.pathname获取离开主机的URL

您可以阅读更多内容

,因此您计划将当前打开的页面的url与拖缆的url进行比较,以查看它们是否匹配?我对此不太熟悉,但我认为您可以在chrome中监视资源使用情况。这样,如果他们在另一个浏览器中打开了流,它仍然会检测到它。请尝试查看:,或者您计划将他们当前打开的页面的url与拖缆的url进行比较,以查看它们是否匹配?我对此不太熟悉,但我认为您可以在chrome中监视资源使用情况。这样,如果他们在另一个浏览器中打开了流,它仍然会检测到它。请尝试查看:,或者您计划将他们当前打开的页面的url与拖缆的url进行比较,以查看它们是否匹配?我对此不太熟悉,但我认为您可以在chrome中监视资源使用情况。这样,如果他们在另一个浏览器中打开该流,它仍会检测到它。请尝试查看:,或