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);
|
||||
svgRoot.removeEventListener('mousemove', onSvgHovered);
|
||||
svgRoot.removeEventListener('click', onSvgClicked);
|
||||
document.body.removeChild(pickerRoot);
|
||||
pickerRoot.parentNode.removeChild(pickerRoot)
|
||||
pickerRoot =
|
||||
divDialog =
|
||||
svgRoot = svgOcean = svgIslands =
|
||||
|
@ -684,7 +684,7 @@ var startPicker = function() {
|
|||
var pickerStyle = document.createElement('style');
|
||||
pickerStyle.setAttribute('scoped', '');
|
||||
pickerStyle.textContent = [
|
||||
'#µBlock, #µBlock * {',
|
||||
'#µBlock, #µBlock * {',
|
||||
'background: transparent;',
|
||||
'background-image: none;',
|
||||
'border: 0;',
|
||||
|
@ -766,7 +766,6 @@ var startPicker = function() {
|
|||
'font: 12px sans-serif;',
|
||||
'background-color: rgba(255,255,255,0.9);',
|
||||
'z-index: 5999999999;',
|
||||
'direction: ', chrome.i18n.getMessage('@@bidi_dir'), ';',
|
||||
'}',
|
||||
'#µBlock.paused > div {',
|
||||
'opacity: 0.2;',
|
||||
|
@ -900,6 +899,7 @@ var startPicker = function() {
|
|||
|
||||
var initPicker = function(details) {
|
||||
var i18nMap = {
|
||||
'#µBlock > div': '@@bidi_dir',
|
||||
'#create': 'create',
|
||||
'#pick': 'pick',
|
||||
'#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(2)': 'cosmeticFiltersHint'
|
||||
};
|
||||
|
||||
if (details.i18n['@@bidi_dir']) {
|
||||
divDialog.style.direction = details.i18n['@@bidi_dir'];
|
||||
delete i18nMap['#µBlock > div'];
|
||||
}
|
||||
|
||||
for ( var k in i18nMap ) {
|
||||
if ( i18nMap.hasOwnProperty(k) === false ) {
|
||||
continue;
|
||||
|
|
|
@ -339,44 +339,13 @@ var onMessage = function(details, sender, callback) {
|
|||
response = filterRequest(pageStore, details);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
callback(response);
|
||||
};
|
||||
|
||||
vAPI.messaging.listen('contentscript-end.js', onMessage);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
})();
|
||||
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
// 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 ) {
|
||||
// the following is used by element-picker.js
|
||||
case 'elementPickerArguments':
|
||||
response = {
|
||||
i18n: {
|
||||
'@@bidi_dir': vAPI.i18n('@@bidi_dir'),
|
||||
create: vAPI.i18n('pickerCreate'),
|
||||
pick: vAPI.i18n('pickerPick'),
|
||||
quit: vAPI.i18n('pickerQuit'),
|
||||
|
@ -402,7 +371,7 @@ var onMessage = function(request, sender, callback) {
|
|||
callback(response);
|
||||
};
|
||||
|
||||
vAPI.messaging.listen('element-picker.js', onMessage);
|
||||
vAPI.messaging.listen('contentscript-end.js', onMessage);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
|
|
Loading…
Reference in New Issue