mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-16 23:42:39 +01:00
Safari: make toolbar icon more robust & performant
Gets rid of background page exceptions
This commit is contained in:
parent
25222c1439
commit
21d4307a5a
@ -507,17 +507,22 @@
|
|||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
vAPI.toolbarItem = false;
|
vAPI.toolbarItem = false;
|
||||||
safari.application.addEventListener("validate", function(event) {
|
var getIconForWindow = function(target) {
|
||||||
if(vAPI.toolbarItem === event.target) {
|
var items = safari.extension.toolbarItems;
|
||||||
return;
|
for(var i = 0, n = items.length; i < n; i++) {
|
||||||
|
if(items[i].browserWindow === target) {
|
||||||
|
return items[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
vAPI.toolbarItem = event.target;
|
};
|
||||||
}, true);
|
|
||||||
safari.application.addEventListener("activate", function(event) {
|
safari.application.addEventListener("activate", function(event) {
|
||||||
if(!(event.target instanceof SafariBrowserTab)) {
|
var target = event.target;
|
||||||
return;
|
if(target instanceof SafariBrowserTab) {
|
||||||
|
vAPI.updateIcon(vAPI.tabs.getTabId(target));
|
||||||
|
}
|
||||||
|
else if(target instanceof SafariBrowserWindow) {
|
||||||
|
vAPI.toolbarItem = getIconForWindow(target);
|
||||||
}
|
}
|
||||||
vAPI.updateIcon(vAPI.toolbarItem);
|
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@ -538,9 +543,12 @@
|
|||||||
TabIconState.prototype.img = "";
|
TabIconState.prototype.img = "";
|
||||||
|
|
||||||
vAPI.tabIconState = { /*tabId: {badge: 0, img: suffix}*/ };
|
vAPI.tabIconState = { /*tabId: {badge: 0, img: suffix}*/ };
|
||||||
vAPI.updateIcon = function(icon) {
|
vAPI.updateIcon = function(tabId) {
|
||||||
var tabId = vAPI.tabs.getTabId(icon.browserWindow.activeTab),
|
var icon = vAPI.toolbarItem;
|
||||||
state = vAPI.tabIconState[tabId];
|
if(icon === false) {
|
||||||
|
icon = getIconForWindow(vAPI.tabs.stack[tabId].browserWindow);
|
||||||
|
}
|
||||||
|
var state = vAPI.tabIconState[tabId];
|
||||||
if(typeof state === "undefined") {
|
if(typeof state === "undefined") {
|
||||||
state = vAPI.tabIconState[tabId] = new TabIconState();
|
state = vAPI.tabIconState[tabId] = new TabIconState();
|
||||||
}
|
}
|
||||||
@ -554,7 +562,7 @@
|
|||||||
}
|
}
|
||||||
state.badge = badge || 0;
|
state.badge = badge || 0;
|
||||||
state.img = (iconStatus === "on" ? "" : "-off");
|
state.img = (iconStatus === "on" ? "" : "-off");
|
||||||
vAPI.updateIcon(vAPI.toolbarItem);
|
vAPI.updateIcon(tabId);
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
Loading…
Reference in New Issue
Block a user