2

I have written an extension, which changing his icon on websites, who matches the if clause. Take a look:

chrome.tabs.onActivated.addListener(
    function (activeInfo) {
            chrome.tabs.get(activeInfo.tabId, function(tab){
                hosterRegExp(tab.url); //Function to change Icon

        });     
    }
);

chrome.tabs.onUpdated.addListener(
    function checkHosts(tabId, changeInfo, tab) {
        hosterRegExp(tab.url); //Function to change Icon
}
);

Every time the active tab is changed or a tab is getting reloaded the function hosterRegExp is called with the current URL. This works fine.

Now, that's not working with two windows. If I change between two windows, it doesn't call the hosterRegExp(); that's because the active tab is not reloaded nor is it changing the active tab.

Also I couldn't find another EventHandler which would help me. So I have to check also the current windowID? I don't know - please help me.

Thank you.

4

1 回答 1

3

就像 RobW 告诉我的那样,我正在使用

  chrome.windows.onFocusChanged

现在API。

好吧,就我而言,它看起来像这样:

chrome.windows.onFocusChanged.addListener(function() 
{
    chrome.tabs.query({currentWindow: true, active: true}, function(tab)
    {
        hosterRegExp(tab[0].url);
    }); 
});

我使用查询方法来获取更改焦点后的选项卡。尽管在一个窗口中不可能有 2 个选项卡处于活动状态,但该数组每次只有一个元素。

这不漂亮,如果有人有更好更干净的代码,请告诉我!

于 2013-10-05T23:28:37.083 回答