mirror of https://github.com/gorhill/uBlock.git
element-picker fixes, changes
- Include latest changes from gorhill/uBlock/master - Append the pickerRoot container to document.documentElement instead of document.body ("body > div" type CSS selectors are more common, so they could overwrite the extension's styling with higher probability) - Request localized strings from the background script instead of using the i18n API in content scripts - Fuse element-picker.js' message handling into contentscript-end.js', since only one messaging channel can live at a time in a content script
This commit is contained in:
parent
f9602fa5a7
commit
88a7910bcb
|
@ -660,7 +660,7 @@ var stopPicker = function() {
|
||||||
divDialog.removeEventListener('click', onDialogClicked);
|
divDialog.removeEventListener('click', onDialogClicked);
|
||||||
svgRoot.removeEventListener('mousemove', onSvgHovered);
|
svgRoot.removeEventListener('mousemove', onSvgHovered);
|
||||||
svgRoot.removeEventListener('click', onSvgClicked);
|
svgRoot.removeEventListener('click', onSvgClicked);
|
||||||
document.body.removeChild(pickerRoot);
|
pickerRoot.parentNode.removeChild(pickerRoot)
|
||||||
pickerRoot =
|
pickerRoot =
|
||||||
divDialog =
|
divDialog =
|
||||||
svgRoot = svgOcean = svgIslands =
|
svgRoot = svgOcean = svgIslands =
|
||||||
|
@ -684,7 +684,7 @@ var startPicker = function() {
|
||||||
var pickerStyle = document.createElement('style');
|
var pickerStyle = document.createElement('style');
|
||||||
pickerStyle.setAttribute('scoped', '');
|
pickerStyle.setAttribute('scoped', '');
|
||||||
pickerStyle.textContent = [
|
pickerStyle.textContent = [
|
||||||
'#µBlock, #µBlock * {',
|
'#µBlock, #µBlock * {',
|
||||||
'background: transparent;',
|
'background: transparent;',
|
||||||
'background-image: none;',
|
'background-image: none;',
|
||||||
'border: 0;',
|
'border: 0;',
|
||||||
|
@ -766,7 +766,6 @@ var startPicker = function() {
|
||||||
'font: 12px sans-serif;',
|
'font: 12px sans-serif;',
|
||||||
'background-color: rgba(255,255,255,0.9);',
|
'background-color: rgba(255,255,255,0.9);',
|
||||||
'z-index: 5999999999;',
|
'z-index: 5999999999;',
|
||||||
'direction: ', chrome.i18n.getMessage('@@bidi_dir'), ';',
|
|
||||||
'}',
|
'}',
|
||||||
'#µBlock.paused > div {',
|
'#µBlock.paused > div {',
|
||||||
'opacity: 0.2;',
|
'opacity: 0.2;',
|
||||||
|
@ -900,6 +899,7 @@ var startPicker = function() {
|
||||||
|
|
||||||
var initPicker = function(details) {
|
var initPicker = function(details) {
|
||||||
var i18nMap = {
|
var i18nMap = {
|
||||||
|
'#µBlock > div': '@@bidi_dir',
|
||||||
'#create': 'create',
|
'#create': 'create',
|
||||||
'#pick': 'pick',
|
'#pick': 'pick',
|
||||||
'#quit': 'quit',
|
'#quit': 'quit',
|
||||||
|
@ -907,6 +907,12 @@ var startPicker = function() {
|
||||||
'ul > li#cosmeticFilters > span:nth-of-type(1)': 'cosmeticFilters',
|
'ul > li#cosmeticFilters > span:nth-of-type(1)': 'cosmeticFilters',
|
||||||
'ul > li#cosmeticFilters > span:nth-of-type(2)': 'cosmeticFiltersHint'
|
'ul > li#cosmeticFilters > span:nth-of-type(2)': 'cosmeticFiltersHint'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (details.i18n['@@bidi_dir']) {
|
||||||
|
divDialog.style.direction = details.i18n['@@bidi_dir'];
|
||||||
|
delete i18nMap['#µBlock > div'];
|
||||||
|
}
|
||||||
|
|
||||||
for ( var k in i18nMap ) {
|
for ( var k in i18nMap ) {
|
||||||
if ( i18nMap.hasOwnProperty(k) === false ) {
|
if ( i18nMap.hasOwnProperty(k) === false ) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -339,44 +339,13 @@ var onMessage = function(details, sender, callback) {
|
||||||
response = filterRequest(pageStore, details);
|
response = filterRequest(pageStore, details);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
callback(response);
|
|
||||||
};
|
|
||||||
|
|
||||||
vAPI.messaging.listen('contentscript-end.js', onMessage);
|
// the following is used by element-picker.js
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
})();
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
// element-picker.js
|
|
||||||
|
|
||||||
(function() {
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
var µb = µBlock;
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
var onMessage = function(request, sender, callback) {
|
|
||||||
// Async
|
|
||||||
switch ( request.what ) {
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sync
|
|
||||||
var response;
|
|
||||||
|
|
||||||
switch ( request.what ) {
|
|
||||||
case 'elementPickerArguments':
|
case 'elementPickerArguments':
|
||||||
response = {
|
response = {
|
||||||
i18n: {
|
i18n: {
|
||||||
|
'@@bidi_dir': vAPI.i18n('@@bidi_dir'),
|
||||||
create: vAPI.i18n('pickerCreate'),
|
create: vAPI.i18n('pickerCreate'),
|
||||||
pick: vAPI.i18n('pickerPick'),
|
pick: vAPI.i18n('pickerPick'),
|
||||||
quit: vAPI.i18n('pickerQuit'),
|
quit: vAPI.i18n('pickerQuit'),
|
||||||
|
@ -402,7 +371,7 @@ var onMessage = function(request, sender, callback) {
|
||||||
callback(response);
|
callback(response);
|
||||||
};
|
};
|
||||||
|
|
||||||
vAPI.messaging.listen('element-picker.js', onMessage);
|
vAPI.messaging.listen('contentscript-end.js', onMessage);
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue