mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-10 09:07:54 +01:00
Miscellaneous changes
This commit is contained in:
parent
a71c967613
commit
e0f214961d
10 changed files with 249 additions and 192 deletions
|
@ -63,7 +63,7 @@ const contentObserver = {
|
||||||
},
|
},
|
||||||
|
|
||||||
QueryInterface: (function() {
|
QueryInterface: (function() {
|
||||||
let {XPCOMUtils} = Cu.import('resource://gre/modules/XPCOMUtils.jsm', {});
|
let {XPCOMUtils} = Cu.import('resource://gre/modules/XPCOMUtils.jsm', null);
|
||||||
|
|
||||||
return XPCOMUtils.generateQI([
|
return XPCOMUtils.generateQI([
|
||||||
Ci.nsIFactory,
|
Ci.nsIFactory,
|
||||||
|
@ -117,7 +117,7 @@ const contentObserver = {
|
||||||
return this.ACCEPT;
|
return this.ACCEPT;
|
||||||
}
|
}
|
||||||
|
|
||||||
var opener;
|
let openerURL;
|
||||||
|
|
||||||
if ( location.scheme !== 'http' && location.scheme !== 'https' ) {
|
if ( location.scheme !== 'http' && location.scheme !== 'https' ) {
|
||||||
if ( type !== this.MAIN_FRAME ) {
|
if ( type !== this.MAIN_FRAME ) {
|
||||||
|
@ -127,10 +127,10 @@ const contentObserver = {
|
||||||
context = context.contentWindow || context;
|
context = context.contentWindow || context;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
opener = context.opener.location.href;
|
openerURL = context.opener.location.href;
|
||||||
} catch (ex) {}
|
} catch (ex) {}
|
||||||
|
|
||||||
let isPopup = location.spec === 'about:blank' && opener;
|
let isPopup = location.spec === 'about:blank' && openerURL;
|
||||||
|
|
||||||
if ( location.scheme !== 'data' && !isPopup ) {
|
if ( location.scheme !== 'data' && !isPopup ) {
|
||||||
return this.ACCEPT;
|
return this.ACCEPT;
|
||||||
|
@ -139,7 +139,7 @@ const contentObserver = {
|
||||||
context = context.contentWindow || context;
|
context = context.contentWindow || context;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
opener = context.opener.location.href;
|
openerURL = context.opener.location.href;
|
||||||
} catch (ex) {}
|
} catch (ex) {}
|
||||||
} else {
|
} else {
|
||||||
context = (context.ownerDocument || context).defaultView;
|
context = (context.ownerDocument || context).defaultView;
|
||||||
|
@ -150,7 +150,7 @@ const contentObserver = {
|
||||||
if ( context.top && context.location ) {
|
if ( context.top && context.location ) {
|
||||||
// https://bugzil.la/1092216
|
// https://bugzil.la/1092216
|
||||||
getMessageManager(context).sendRpcMessage(this.cpMessageName, {
|
getMessageManager(context).sendRpcMessage(this.cpMessageName, {
|
||||||
opener: opener || null,
|
openerURL: openerURL || null,
|
||||||
url: location.spec,
|
url: location.spec,
|
||||||
type: type,
|
type: type,
|
||||||
frameId: type === this.MAIN_FRAME ? -1 : (context === context.top ? 0 : 1),
|
frameId: type === this.MAIN_FRAME ? -1 : (context === context.top ? 0 : 1),
|
||||||
|
@ -215,14 +215,19 @@ const contentObserver = {
|
||||||
);
|
);
|
||||||
}.bind(sandbox);
|
}.bind(sandbox);
|
||||||
sandbox.removeMessageListener = function() {
|
sandbox.removeMessageListener = function() {
|
||||||
messager.removeMessageListener(
|
try {
|
||||||
this._sandboxId_,
|
messager.removeMessageListener(
|
||||||
this._messageListener_
|
this._sandboxId_,
|
||||||
);
|
this._messageListener_
|
||||||
messager.removeMessageListener(
|
);
|
||||||
hostName + ':broadcast',
|
messager.removeMessageListener(
|
||||||
this._messageListener_
|
hostName + ':broadcast',
|
||||||
);
|
this._messageListener_
|
||||||
|
);
|
||||||
|
} catch (ex) {
|
||||||
|
// It throws sometimes, mostly when the popup closes
|
||||||
|
}
|
||||||
|
|
||||||
this._messageListener_ = null;
|
this._messageListener_ = null;
|
||||||
}.bind(sandbox);
|
}.bind(sandbox);
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
Home: https://github.com/gorhill/uBlock
|
Home: https://github.com/gorhill/uBlock
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
Components.utils.import(
|
Components.utils.import(
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<r:Description>
|
<r:Description>
|
||||||
<id>{{ec8030f7-c20a-464f-9b0e-13a3a9e97384}}</id>
|
<id>{{ec8030f7-c20a-464f-9b0e-13a3a9e97384}}</id>
|
||||||
<minVersion>29.0</minVersion>
|
<minVersion>29.0</minVersion>
|
||||||
<maxVersion>37.0</maxVersion>
|
<maxVersion>38.0</maxVersion>
|
||||||
</r:Description>
|
</r:Description>
|
||||||
</targetApplication>
|
</targetApplication>
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
<r:Description>
|
<r:Description>
|
||||||
<id>{{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}}</id>
|
<id>{{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}}</id>
|
||||||
<minVersion>2.26</minVersion>
|
<minVersion>2.26</minVersion>
|
||||||
<maxVersion>2.34</maxVersion>
|
<maxVersion>2.35</maxVersion>
|
||||||
</r:Description>
|
</r:Description>
|
||||||
</targetApplication>
|
</targetApplication>
|
||||||
</r:Description>
|
</r:Description>
|
||||||
|
|
|
@ -42,7 +42,7 @@ vAPI.firefox = true;
|
||||||
// TODO: read these data from somewhere...
|
// TODO: read these data from somewhere...
|
||||||
vAPI.app = {
|
vAPI.app = {
|
||||||
name: 'µBlock',
|
name: 'µBlock',
|
||||||
version: '0.8.2.3'
|
version: '0.8.5.0'
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
@ -248,7 +248,7 @@ var windowWatcher = {
|
||||||
onTabClose: function(e) {
|
onTabClose: function(e) {
|
||||||
var tabId = vAPI.tabs.getTabId(e.target);
|
var tabId = vAPI.tabs.getTabId(e.target);
|
||||||
vAPI.tabs.onClosed(tabId);
|
vAPI.tabs.onClosed(tabId);
|
||||||
delete vAPI.tabIcons[tabId];
|
delete vAPI.toolbarButton.tabs[tabId];
|
||||||
},
|
},
|
||||||
|
|
||||||
onTabSelect: function(e) {
|
onTabSelect: function(e) {
|
||||||
|
@ -279,7 +279,6 @@ var windowWatcher = {
|
||||||
tC.addEventListener('TabClose', windowWatcher.onTabClose);
|
tC.addEventListener('TabClose', windowWatcher.onTabClose);
|
||||||
tC.addEventListener('TabSelect', windowWatcher.onTabSelect);
|
tC.addEventListener('TabSelect', windowWatcher.onTabSelect);
|
||||||
|
|
||||||
vAPI.toolbarButton.register(this.document);
|
|
||||||
vAPI.contextMenu.register(this.document);
|
vAPI.contextMenu.register(this.document);
|
||||||
|
|
||||||
// when new window is opened TabSelect doesn't run on the selected tab?
|
// when new window is opened TabSelect doesn't run on the selected tab?
|
||||||
|
@ -334,13 +333,11 @@ vAPI.tabs.registerListeners = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Services.ww.registerNotification(windowWatcher);
|
Services.ww.registerNotification(windowWatcher);
|
||||||
vAPI.toolbarButton.init();
|
|
||||||
|
|
||||||
vAPI.unload.push(function() {
|
vAPI.unload.push(function() {
|
||||||
Services.ww.unregisterNotification(windowWatcher);
|
Services.ww.unregisterNotification(windowWatcher);
|
||||||
|
|
||||||
for ( var win of vAPI.tabs.getWindows() ) {
|
for ( var win of vAPI.tabs.getWindows() ) {
|
||||||
vAPI.toolbarButton.unregister(win.document);
|
|
||||||
vAPI.contextMenu.unregister(win.document);
|
vAPI.contextMenu.unregister(win.document);
|
||||||
|
|
||||||
win.removeEventListener('DOMContentLoaded', windowWatcher.onReady);
|
win.removeEventListener('DOMContentLoaded', windowWatcher.onReady);
|
||||||
|
@ -600,19 +597,19 @@ vAPI.tabs.injectScript = function(tabId, details, callback) {
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
vAPI.tabIcons = { /*tabId: {badge: 0, img: boolean}*/ };
|
|
||||||
vAPI.setIcon = function(tabId, iconStatus, badge) {
|
vAPI.setIcon = function(tabId, iconStatus, badge) {
|
||||||
// If badge is undefined, then setIcon was called from the TabSelect event
|
// If badge is undefined, then setIcon was called from the TabSelect event
|
||||||
var curWin = badge === undefined
|
var win = badge === undefined
|
||||||
? iconStatus
|
? iconStatus
|
||||||
: Services.wm.getMostRecentWindow('navigator:browser');
|
: Services.wm.getMostRecentWindow('navigator:browser');
|
||||||
var curTabId = vAPI.tabs.getTabId(curWin.gBrowser.selectedTab);
|
var curTabId = vAPI.tabs.getTabId(win.gBrowser.selectedTab);
|
||||||
|
var tb = vAPI.toolbarButton;
|
||||||
|
|
||||||
// from 'TabSelect' event
|
// from 'TabSelect' event
|
||||||
if ( tabId === undefined ) {
|
if ( tabId === undefined ) {
|
||||||
tabId = curTabId;
|
tabId = curTabId;
|
||||||
} else if ( badge !== undefined ) {
|
} else if ( badge !== undefined ) {
|
||||||
vAPI.tabIcons[tabId] = {
|
tb.tabs[tabId] = {
|
||||||
badge: badge,
|
badge: badge,
|
||||||
img: iconStatus === 'on'
|
img: iconStatus === 'on'
|
||||||
};
|
};
|
||||||
|
@ -622,166 +619,23 @@ vAPI.setIcon = function(tabId, iconStatus, badge) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var button = curWin.document.getElementById(vAPI.toolbarButton.widgetId);
|
var button = win.document.getElementById(tb.id);
|
||||||
|
|
||||||
if ( !button ) {
|
if ( !button ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*if ( !button.classList.contains('badged-button') ) {
|
var icon = tb.tabs[tabId];
|
||||||
button.classList.add('badged-button');
|
|
||||||
}*/
|
|
||||||
|
|
||||||
var icon = vAPI.tabIcons[tabId];
|
|
||||||
button.setAttribute('badge', icon && icon.badge || '');
|
button.setAttribute('badge', icon && icon.badge || '');
|
||||||
iconStatus = !button.image || !icon || !icon.img ? '-off' : '';
|
|
||||||
button.image = vAPI.getURL('img/browsericons/icon16' + iconStatus + '.svg');
|
|
||||||
};
|
|
||||||
|
|
||||||
/******************************************************************************/
|
if ( !icon || !icon.img ) {
|
||||||
|
icon = '';
|
||||||
vAPI.toolbarButton = {
|
}
|
||||||
widgetId: location.host + '-button',
|
else {
|
||||||
panelId: location.host + '-panel'
|
icon = 'url(' + vAPI.getURL('img/browsericons/icon16.svg') + ')';
|
||||||
};
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
vAPI.toolbarButton.init = function() {
|
|
||||||
const {CustomizableUI} = Cu.import('resource:///modules/CustomizableUI.jsm', {});
|
|
||||||
|
|
||||||
CustomizableUI.createWidget({
|
|
||||||
id: this.widgetId,
|
|
||||||
type: 'view',
|
|
||||||
viewId: this.panelId,
|
|
||||||
defaultArea: CustomizableUI.AREA_NAVBAR,
|
|
||||||
label: vAPI.app.name,
|
|
||||||
tooltiptext: vAPI.app.name,
|
|
||||||
onViewShowing: function({target}) {
|
|
||||||
var hash = CustomizableUI.getWidget(vAPI.toolbarButton.widgetId)
|
|
||||||
.areaType === CustomizableUI.TYPE_TOOLBAR ? '' : '#body';
|
|
||||||
|
|
||||||
target.firstChild.setAttribute(
|
|
||||||
'src',
|
|
||||||
vAPI.getURL('popup.html' + hash)
|
|
||||||
);
|
|
||||||
},
|
|
||||||
onViewHiding: function({target}) {
|
|
||||||
target.firstChild.setAttribute('src', 'about:blank');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.closePopup = function({target}) {
|
|
||||||
CustomizableUI.hidePanelForNode(
|
|
||||||
target.ownerDocument.getElementById(vAPI.toolbarButton.panelId)
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
vAPI.messaging.globalMessageManager.addMessageListener(
|
|
||||||
location.host + ':closePopup',
|
|
||||||
this.closePopup
|
|
||||||
);
|
|
||||||
|
|
||||||
vAPI.unload.push(function() {
|
|
||||||
CustomizableUI.destroyWidget(vAPI.toolbarButton.widgetId);
|
|
||||||
vAPI.messaging.globalMessageManager.removeMessageListener(
|
|
||||||
location.host + ':closePopup',
|
|
||||||
vAPI.toolbarButton.closePopup
|
|
||||||
);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
// it runs with windowWatcher when a window is opened
|
|
||||||
// vAPI.tabs.registerListeners initializes it
|
|
||||||
|
|
||||||
vAPI.toolbarButton.register = function(doc) {
|
|
||||||
var panel = doc.createElement('panelview');
|
|
||||||
panel.setAttribute('id', this.panelId);
|
|
||||||
|
|
||||||
var iframe = doc.createElement('iframe');
|
|
||||||
iframe.setAttribute('type', 'content');
|
|
||||||
|
|
||||||
doc.getElementById('PanelUI-multiView')
|
|
||||||
.appendChild(panel)
|
|
||||||
.appendChild(iframe);
|
|
||||||
|
|
||||||
var updateTimer = null;
|
|
||||||
var delayedResize = function() {
|
|
||||||
if ( updateTimer ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
updateTimer = setTimeout(resizePopup, 20);
|
|
||||||
};
|
|
||||||
|
|
||||||
var resizePopup = function() {
|
|
||||||
var panelStyle = panel.style;
|
|
||||||
var body = iframe.contentDocument.body;
|
|
||||||
panelStyle.width = iframe.style.width = body.clientWidth + 'px';
|
|
||||||
panelStyle.height = iframe.style.height = body.clientHeight + 'px';
|
|
||||||
updateTimer = null;
|
|
||||||
};
|
|
||||||
|
|
||||||
var onPopupReady = function() {
|
|
||||||
var win = this.contentWindow;
|
|
||||||
|
|
||||||
if ( !win || win.location.host !== location.host ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
new win.MutationObserver(delayedResize).observe(win.document, {
|
|
||||||
childList: true,
|
|
||||||
attributes: true,
|
|
||||||
characterData: true,
|
|
||||||
subtree: true
|
|
||||||
});
|
|
||||||
|
|
||||||
delayedResize();
|
|
||||||
};
|
|
||||||
|
|
||||||
iframe.addEventListener('load', onPopupReady, true);
|
|
||||||
|
|
||||||
if ( !this.styleURI ) {
|
|
||||||
this.styleURI = 'data:text/css,' + encodeURIComponent([
|
|
||||||
'#' + this.widgetId + ' {',
|
|
||||||
'list-style-image: url(',
|
|
||||||
vAPI.getURL('img/browsericons/icon16-off.svg'),
|
|
||||||
');',
|
|
||||||
'}',
|
|
||||||
'#' + this.widgetId + '[badge]:not([badge=""])::after {',
|
|
||||||
'position: absolute;',
|
|
||||||
'margin-left: -16px;',
|
|
||||||
'margin-top: 3px;',
|
|
||||||
'padding: 1px 2px;',
|
|
||||||
'font-size: 9px;',
|
|
||||||
'font-weight: bold;',
|
|
||||||
'color: #fff;',
|
|
||||||
'background: #666;',
|
|
||||||
'content: attr(badge);',
|
|
||||||
'}',
|
|
||||||
'#' + this.panelId + ', #' + this.panelId + ' > iframe {',
|
|
||||||
'width: 180px;',
|
|
||||||
'height: 310px;',
|
|
||||||
'overflow: hidden !important;',
|
|
||||||
'}'
|
|
||||||
].join(''));
|
|
||||||
|
|
||||||
this.styleURI = Services.io.newURI(this.styleURI, null, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
doc.defaultView.QueryInterface(Ci.nsIInterfaceRequestor).
|
button.style.listStyleImage = icon;
|
||||||
getInterface(Ci.nsIDOMWindowUtils).loadSheet(this.styleURI, 1);
|
|
||||||
};
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
vAPI.toolbarButton.unregister = function(doc) {
|
|
||||||
var panel = doc.getElementById(this.panelId);
|
|
||||||
panel.parentNode.removeChild(panel);
|
|
||||||
doc.defaultView.QueryInterface(Ci.nsIInterfaceRequestor).
|
|
||||||
getInterface(Ci.nsIDOMWindowUtils).removeSheet(this.styleURI, 1);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
@ -933,7 +787,7 @@ var httpObserver = {
|
||||||
tabId: null,
|
tabId: null,
|
||||||
frameId: null,
|
frameId: null,
|
||||||
parentFrameId: null,
|
parentFrameId: null,
|
||||||
opener: null
|
openerURL: null
|
||||||
},
|
},
|
||||||
|
|
||||||
get componentRegistrar() {
|
get componentRegistrar() {
|
||||||
|
@ -946,7 +800,7 @@ var httpObserver = {
|
||||||
},
|
},
|
||||||
|
|
||||||
QueryInterface: (function() {
|
QueryInterface: (function() {
|
||||||
var {XPCOMUtils} = Cu.import('resource://gre/modules/XPCOMUtils.jsm', {});
|
var {XPCOMUtils} = Cu.import('resource://gre/modules/XPCOMUtils.jsm', null);
|
||||||
|
|
||||||
return XPCOMUtils.generateQI([
|
return XPCOMUtils.generateQI([
|
||||||
Ci.nsIFactory,
|
Ci.nsIFactory,
|
||||||
|
@ -1113,12 +967,12 @@ var httpObserver = {
|
||||||
var sourceTabId = null;
|
var sourceTabId = null;
|
||||||
|
|
||||||
// popup candidate (only for main_frame type)
|
// popup candidate (only for main_frame type)
|
||||||
if ( lastRequest.opener ) {
|
if ( lastRequest.openerURL ) {
|
||||||
for ( var tab of vAPI.tabs.getAll() ) {
|
for ( var tab of vAPI.tabs.getAll() ) {
|
||||||
var tabURI = tab.linkedBrowser.currentURI;
|
var tabURI = tab.linkedBrowser.currentURI;
|
||||||
|
|
||||||
// not the best approach
|
// not the best approach
|
||||||
if ( tabURI.spec === this.lastRequest.opener ) {
|
if ( tabURI.spec === this.lastRequest.openerURL ) {
|
||||||
sourceTabId = vAPI.tabs.getTabId(tab);
|
sourceTabId = vAPI.tabs.getTabId(tab);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1205,6 +1059,9 @@ vAPI.net = {};
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
vAPI.net.registerListeners = function() {
|
vAPI.net.registerListeners = function() {
|
||||||
|
// Since it's not used
|
||||||
|
this.onBeforeSendHeaders = null;
|
||||||
|
|
||||||
this.onBeforeRequest.types = new Set(this.onBeforeRequest.types);
|
this.onBeforeRequest.types = new Set(this.onBeforeRequest.types);
|
||||||
|
|
||||||
var shouldLoadListenerMessageName = location.host + ':shouldLoad';
|
var shouldLoadListenerMessageName = location.host + ':shouldLoad';
|
||||||
|
@ -1229,7 +1086,7 @@ vAPI.net.registerListeners = function() {
|
||||||
lastRequest.tabId = vAPI.tabs.getTabId(e.target);
|
lastRequest.tabId = vAPI.tabs.getTabId(e.target);
|
||||||
lastRequest.frameId = details.frameId;
|
lastRequest.frameId = details.frameId;
|
||||||
lastRequest.parentFrameId = details.parentFrameId;
|
lastRequest.parentFrameId = details.parentFrameId;
|
||||||
lastRequest.opener = details.opener;
|
lastRequest.openerURL = details.openerURL;
|
||||||
};
|
};
|
||||||
|
|
||||||
vAPI.messaging.globalMessageManager.addMessageListener(
|
vAPI.messaging.globalMessageManager.addMessageListener(
|
||||||
|
@ -1251,6 +1108,192 @@ vAPI.net.registerListeners = function() {
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
vAPI.toolbarButton = {
|
||||||
|
id: location.host + '-button',
|
||||||
|
type: 'view',
|
||||||
|
viewId: location.host + '-panel',
|
||||||
|
label: vAPI.app.name,
|
||||||
|
tooltiptext: vAPI.app.name,
|
||||||
|
tabs: {/*tabId: {badge: 0, img: boolean}*/}
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
vAPI.toolbarButton.init = function() {
|
||||||
|
var {CustomizableUI} = Cu.import('resource:///modules/CustomizableUI.jsm', null);
|
||||||
|
this.defaultArea = CustomizableUI.AREA_NAVBAR;
|
||||||
|
this.styleURI = [
|
||||||
|
'#' + this.id + ' {',
|
||||||
|
'list-style-image: url(',
|
||||||
|
vAPI.getURL('img/browsericons/icon16-off.svg'),
|
||||||
|
');',
|
||||||
|
'}',
|
||||||
|
'#' + this.viewId + ', #' + this.viewId + ' > iframe {',
|
||||||
|
'width: 160px;',
|
||||||
|
'height: 290px;',
|
||||||
|
'overflow: hidden !important;',
|
||||||
|
'}'
|
||||||
|
];
|
||||||
|
|
||||||
|
var platformVersion = Services.appinfo.platformVersion;
|
||||||
|
|
||||||
|
if ( Services.vc.compare(platformVersion, '36.0') < 0 ) {
|
||||||
|
this.styleURI.push(
|
||||||
|
'#' + this.id + '[badge]:not([badge=""])::after {',
|
||||||
|
'position: absolute;',
|
||||||
|
'margin-left: -16px;',
|
||||||
|
'margin-top: 3px;',
|
||||||
|
'padding: 1px 2px;',
|
||||||
|
'font-size: 9px;',
|
||||||
|
'font-weight: bold;',
|
||||||
|
'color: #fff;',
|
||||||
|
'background: #666;',
|
||||||
|
'content: attr(badge);',
|
||||||
|
'}'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.styleURI = Services.io.newURI(
|
||||||
|
'data:text/css,' + encodeURIComponent(this.styleURI.join('')),
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
this.closePopup = function({target}) {
|
||||||
|
CustomizableUI.hidePanelForNode(
|
||||||
|
target.ownerDocument.getElementById(vAPI.toolbarButton.viewId)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
CustomizableUI.createWidget(this);
|
||||||
|
vAPI.messaging.globalMessageManager.addMessageListener(
|
||||||
|
location.host + ':closePopup',
|
||||||
|
this.closePopup
|
||||||
|
);
|
||||||
|
|
||||||
|
vAPI.unload.push(function() {
|
||||||
|
CustomizableUI.destroyWidget(this.id);
|
||||||
|
vAPI.messaging.globalMessageManager.removeMessageListener(
|
||||||
|
location.host + ':closePopup',
|
||||||
|
this.closePopup
|
||||||
|
);
|
||||||
|
|
||||||
|
for ( var win of vAPI.tabs.getWindows() ) {
|
||||||
|
var panel = win.document.getElementById(this.viewId);
|
||||||
|
panel.parentNode.removeChild(panel);
|
||||||
|
win.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
|
.getInterface(Ci.nsIDOMWindowUtils)
|
||||||
|
.removeSheet(this.styleURI, 1);
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
vAPI.toolbarButton.onBeforeCreated = function(doc) {
|
||||||
|
var panel = doc.createElement('panelview');
|
||||||
|
panel.setAttribute('id', this.viewId);
|
||||||
|
|
||||||
|
var iframe = doc.createElement('iframe');
|
||||||
|
iframe.setAttribute('type', 'content');
|
||||||
|
|
||||||
|
doc.getElementById('PanelUI-multiView')
|
||||||
|
.appendChild(panel)
|
||||||
|
.appendChild(iframe);
|
||||||
|
|
||||||
|
var updateTimer = null;
|
||||||
|
var delayedResize = function() {
|
||||||
|
if ( updateTimer ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateTimer = setTimeout(resizePopup, 50);
|
||||||
|
};
|
||||||
|
var resizePopup = function() {
|
||||||
|
var body = iframe.contentDocument.body;
|
||||||
|
panel.parentNode.style.maxWidth = 'none';
|
||||||
|
panel.style.width = iframe.style.width = body.clientWidth + 'px';
|
||||||
|
panel.style.height = iframe.style.height = body.clientHeight + 'px';
|
||||||
|
updateTimer = null;
|
||||||
|
};
|
||||||
|
var onPopupReady = function() {
|
||||||
|
var win = this.contentWindow;
|
||||||
|
|
||||||
|
if ( !win || win.location.host !== location.host ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
new win.MutationObserver(delayedResize).observe(win.body, {
|
||||||
|
attributes: true,
|
||||||
|
characterData: true,
|
||||||
|
subtree: true
|
||||||
|
});
|
||||||
|
|
||||||
|
delayedResize();
|
||||||
|
};
|
||||||
|
|
||||||
|
iframe.addEventListener('load', onPopupReady, true);
|
||||||
|
|
||||||
|
doc.defaultView.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
|
.getInterface(Ci.nsIDOMWindowUtils)
|
||||||
|
.loadSheet(this.styleURI, 1);
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
vAPI.toolbarButton.onCreated = function(button) {
|
||||||
|
var platformVersion = Services.appinfo.platformVersion;
|
||||||
|
|
||||||
|
if ( Services.vc.compare(platformVersion, '36.0') < 0 ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
button.setAttribute('badge', '');
|
||||||
|
button.classList.add('badged-button');
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
var badge = button.ownerDocument.getAnonymousElementByAttribute(
|
||||||
|
button,
|
||||||
|
'class',
|
||||||
|
'toolbarbutton-badge'
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( !badge ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
badge.style.cssText = [
|
||||||
|
'position: absolute;',
|
||||||
|
'bottom: 0;',
|
||||||
|
'right: 0;',
|
||||||
|
'padding: 1px;',
|
||||||
|
'background: #666;',
|
||||||
|
'color: #fff;',
|
||||||
|
'font-size: 9px;',
|
||||||
|
'font-weight: bold;'
|
||||||
|
].join('');
|
||||||
|
}, 1000);
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
vAPI.toolbarButton.onViewShowing = function({target}) {
|
||||||
|
target.firstChild.setAttribute('src', vAPI.getURL('popup.html'));
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
vAPI.toolbarButton.onViewHiding = function({target}) {
|
||||||
|
target.parentNode.style.maxWidth = '';
|
||||||
|
target.firstChild.setAttribute('src', 'about:blank');
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
vAPI.toolbarButton.init();
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
vAPI.contextMenu = {
|
vAPI.contextMenu = {
|
||||||
contextMap: {
|
contextMap: {
|
||||||
frame: 'inFrame',
|
frame: 'inFrame',
|
||||||
|
@ -1267,6 +1310,11 @@ vAPI.contextMenu = {
|
||||||
vAPI.contextMenu.displayMenuItem = function(e) {
|
vAPI.contextMenu.displayMenuItem = function(e) {
|
||||||
var doc = e.target.ownerDocument;
|
var doc = e.target.ownerDocument;
|
||||||
var gContextMenu = doc.defaultView.gContextMenu;
|
var gContextMenu = doc.defaultView.gContextMenu;
|
||||||
|
|
||||||
|
if ( !gContextMenu.browser ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var menuitem = doc.getElementById(vAPI.contextMenu.menuItemId);
|
var menuitem = doc.getElementById(vAPI.contextMenu.menuItemId);
|
||||||
|
|
||||||
if ( /^https?$/.test(gContextMenu.browser.currentURI.scheme) === false) {
|
if ( /^https?$/.test(gContextMenu.browser.currentURI.scheme) === false) {
|
||||||
|
|
|
@ -85,7 +85,7 @@ vAPI.i18n = (function() {
|
||||||
try {
|
try {
|
||||||
return stringBundle.GetStringFromName(s);
|
return stringBundle.GetStringFromName(s);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
return s;
|
return '';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -84,7 +84,7 @@
|
||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
<!-- <key>Update Manifest URL</key>
|
<!-- <key>Update Manifest URL</key>
|
||||||
<string>https://github.com/gorhill/uBlock/Safari/Update.plist</string> -->
|
<string>https://raw.githubusercontent.com/gorhill/uBlock/master/dist/Update.plist</string> -->
|
||||||
<key>Website</key>
|
<key>Website</key>
|
||||||
<string>https://github.com/gorhill/uBlock</string>
|
<string>https://github.com/gorhill/uBlock</string>
|
||||||
</dict>
|
</dict>
|
||||||
|
|
|
@ -602,6 +602,10 @@ vAPI.net = {};
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
vAPI.net.registerListeners = function() {
|
vAPI.net.registerListeners = function() {
|
||||||
|
// Since it's not used
|
||||||
|
this.onBeforeSendHeaders = null;
|
||||||
|
this.onHeadersReceived = null;
|
||||||
|
|
||||||
var onBeforeRequest = this.onBeforeRequest;
|
var onBeforeRequest = this.onBeforeRequest;
|
||||||
|
|
||||||
if ( !Array.isArray(onBeforeRequest.types) ) {
|
if ( !Array.isArray(onBeforeRequest.types) ) {
|
||||||
|
|
|
@ -74,12 +74,13 @@ vAPI.getURL = function(path) {
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
// supported languages
|
// Supported languages
|
||||||
// first language is the default
|
// First language is the default
|
||||||
|
|
||||||
vAPI.i18nData = [
|
vAPI.i18nData = [
|
||||||
'en', 'ar', 'cs', 'da', 'de', 'el', 'es', 'et', 'fi', 'fil', 'fr', 'he',
|
'en', 'ar', 'ca', 'cs', 'da', 'de', 'el', 'es', 'et', 'fi', 'fil',
|
||||||
'hi', 'hr', 'hu', 'id', 'it', 'ja', 'mr', 'nb', 'nl', 'pl', 'pt-BR',
|
'fr', 'he', 'hi', 'hr', 'hu', 'id', 'it', 'ja', 'mr', 'nb', 'nl', 'pl',
|
||||||
'pt-PT', 'ro', 'ru', 'sv', 'tr', 'uk', 'vi', 'zh-CN'
|
'pt-BR', 'pt-PT', 'ro', 'ru', 'sv', 'tr', 'uk', 'vi', 'zh-CN', 'zh-TW'
|
||||||
];
|
];
|
||||||
|
|
||||||
vAPI.i18n = navigator.language;
|
vAPI.i18n = navigator.language;
|
||||||
|
|
|
@ -7,9 +7,6 @@ body {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
#body:target {
|
|
||||||
float: none;
|
|
||||||
}
|
|
||||||
h1,h2,h3,h4 {
|
h1,h2,h3,h4 {
|
||||||
background-color: #444;
|
background-color: #444;
|
||||||
border: 0;
|
border: 0;
|
||||||
|
|
|
@ -25,7 +25,7 @@ target_locale_dir = pj(build_dir, 'locale')
|
||||||
language_codes = []
|
language_codes = []
|
||||||
description = ''
|
description = ''
|
||||||
|
|
||||||
for alpha2 in os.listdir(source_locale_dir):
|
for alpha2 in sorted(os.listdir(source_locale_dir)):
|
||||||
locale_path = pj(source_locale_dir, alpha2, 'messages.json')
|
locale_path = pj(source_locale_dir, alpha2, 'messages.json')
|
||||||
with open(locale_path, encoding='utf-8') as f:
|
with open(locale_path, encoding='utf-8') as f:
|
||||||
string_data = json.load(f, object_pairs_hook=OrderedDict)
|
string_data = json.load(f, object_pairs_hook=OrderedDict)
|
||||||
|
|
Loading…
Reference in a new issue