1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-15 15:32:28 +02:00

Merge branch 'master' of github.com:gorhill/uBlock

This commit is contained in:
gorhill 2015-02-19 23:25:38 -05:00
commit e9ee6ab222
2 changed files with 35 additions and 38 deletions

View File

@ -89,7 +89,7 @@ Install from [Firefox Add-ons homepage](https://addons.mozilla.org/en-US/firefox
##### 8.0 or newer only
You can get and install the latest µBlock for Safari [right here](https://chrismatic.io/ublock).
You can get and install the latest µBlock for Safari **[right here](https://chrismatic.io/ublock/)**.
µBlock is also available on the [Safari Extension Gallery](https://extensions.apple.com/details/?id=net.gorhill.uBlock-96G4BAKDQ9), although that's not guaranteed to be the latest version.

View File

@ -27,7 +27,7 @@
(function() {
'use strict';
"use strict";
var vAPI = self.vAPI = self.vAPI || {};
@ -412,29 +412,32 @@
vAPI.tabs.onClosed(tabId);
}
delete vAPI.tabIcons[tabId];
delete vAPI.tabIconState[tabId];
delete vAPI.tabs.stack[tabId];
}
}, true);
/******************************************************************************/
// update badge when tab is activated
safari.application.addEventListener('activate', function(e) {
// ignore windows
if(!(e.target instanceof SafariBrowserTab)) {
vAPI.toolbarItem = false;
safari.application.addEventListener("validate", function(event) {
if(vAPI.toolbarItem === event.target) {
return;
}
// update the badge
vAPI.setIcon(vAPI.tabs.getTabId(e.target));
vAPI.toolbarItem = event.target;
}, true);
safari.application.addEventListener("activate", function(event) {
if(!(event.target instanceof SafariBrowserTab)) {
return;
}
vAPI.updateIcon(vAPI.toolbarItem);
}, true);
/******************************************************************************/
// reload the popup when it's opened
safari.application.addEventListener('popover', function(e) {
var w = e.target.contentWindow, body = w.document.body, child;
safari.application.addEventListener("popover", function(event) {
var w = event.target.contentWindow, body = w.document.body, child;
while(child = body.firstChild) {
body.removeChild(child);
}
@ -442,35 +445,29 @@
}, true);
/******************************************************************************/
function TabIcon() {}
TabIcon.prototype.badge = 0;
TabIcon.prototype.img = "";
vAPI.tabIcons = { /*tabId: {badge: 0, img: suffix}*/ };
function TabIconState() {}
TabIconState.prototype.badge = 0;
TabIconState.prototype.img = "";
vAPI.tabIconState = { /*tabId: {badge: 0, img: suffix}*/ };
vAPI.updateIcon = function(icon) {
var tabId = vAPI.tabs.getTabId(icon.browserWindow.activeTab),
state = vAPI.tabIconState[tabId];
if(typeof state === "undefined") {
state = vAPI.tabIconState[tabId] = new TabIconState();
}
icon.badge = state.badge;
icon.image = vAPI.getURL("img/browsericons/icon16" + state.img + ".png");
};
vAPI.setIcon = function(tabId, iconStatus, badge) {
var icon = vAPI.tabIcons[tabId];
if(typeof icon === "undefined") {
icon = vAPI.tabIcons[tabId] = new TabIcon();
}
// If we've been passed a badge/iconStatus:
if(typeof badge !== "undefined") {
icon.badge = badge;
icon.img = (iconStatus === "on" ? "" : "-off");
}
var items = safari.extension.toolbarItems,
i = items.length;
var curWindow = safari.application.activeBrowserWindow;
while(i --) {
if(items[i].browserWindow === curWindow) {
items[i].badge = icon.badge;
items[i].image = vAPI.getURL("img/browsericons/icon16" +
icon.img + ".png");
return;
}
var state = vAPI.tabIconState[tabId];
if(typeof state === "undefined") {
state = vAPI.tabIconState[tabId] = new TabIconState();
}
state.badge = badge || 0;
state.img = (iconStatus === "on" ? "" : "-off");
vAPI.updateIcon(vAPI.toolbarItem);
};
/******************************************************************************/