1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-10-06 09:37:12 +02:00

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:
Deathamns 2014-10-19 19:36:52 +02:00
parent f9602fa5a7
commit 88a7910bcb
2 changed files with 12 additions and 37 deletions

View File

@ -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;

View File

@ -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);
/******************************************************************************/