Skip to content

Commit

Permalink
Merge pull request #380 in EXTENSIONS/browser-extension from feature/…
Browse files Browse the repository at this point in the history
…1284 to master

* commit 'e1322dc023625d34cd1a247c9757de8127e59655':
  feature/1284 download locales
  feature/1284 fix message text
  feature/1284 if user tries to add existing custom filter show more clear message
  • Loading branch information
maximtop committed Feb 20, 2019
2 parents 38532a2 + e1322dc commit 1ce4ede
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 31 deletions.
36 changes: 21 additions & 15 deletions Extension/_locales/en/messages.json
@@ -1,4 +1,19 @@
{
"options_popup_title_placeholder": {
"message": "Enter a filter name"
},
"options_filters_list_search_display_option_all": {
"message": "All"
},
"options_filters_list_search_display_option_enabled": {
"message": "Enabled"
},
"options_filters_list_search_display_option_disabled": {
"message": "Disabled"
},
"options_disable_webrtc_description": {
"message": "Prevent a possible disclosure of your real IP address even with proxy or VPN through WebRTC"
},
"options_popup_import_settings_wrong_file_extension": {
"message": "The file extension should be .json"
},
Expand Down Expand Up @@ -47,9 +62,6 @@
"options_popup_url_placeholder": {
"message": "Enter URL or path"
},
"options_popup_title_placeholder": {
"message": "Enter a filter name"
},
"options_popup_cancel_button": {
"message": "Cancel"
},
Expand Down Expand Up @@ -164,6 +176,9 @@
"options_antibanner_custom_group": {
"message": "Custom"
},
"options_antibanner_custom_filter_already_exists": {
"message": "This custom filter has already been added"
},
"options_filters_enabled": {
"message": "Enabled:"
},
Expand Down Expand Up @@ -209,15 +224,6 @@
"options_filters_list_search_placeholder": {
"message": "Enter the search string"
},
"options_filters_list_search_display_option_all": {
"message": "All"
},
"options_filters_list_search_display_option_enabled": {
"message": "Enabled"
},
"options_filters_list_search_display_option_disabled": {
"message": "Disabled"
},
"options_popup_import_error_description": {
"message": "Something went wrong"
},
Expand Down Expand Up @@ -791,8 +797,8 @@
"options_disable_webrtc_title": {
"message": "Block WebRTC"
},
"options_disable_webrtc_description": {
"message": "Prevent a possible disclosure of your real IP address even with proxy or VPN through WebRTC"
"options_disable_webrtc_desc": {
"message": "It can let others know your real IP address even if you use proxy or VPN"
},
"options_strip_tracking_params_title": {
"message": "Remove tracking parameters"
Expand Down Expand Up @@ -902,4 +908,4 @@
"options_delete_filter_confirm": {
"message": "Are you sure you want to delete this filter?"
}
}
}
6 changes: 3 additions & 3 deletions Extension/lib/content-message-handler.js
Expand Up @@ -192,9 +192,9 @@
break;
case 'loadCustomFilterInfo':
adguard.filters.loadCustomFilterInfo(message.url, { title: message.title }, (filter) => {
callback(filter);
}, () => {
callback();
callback({ filter });
}, (error) => {
callback({ error });
});
return true;
case 'subscribeToCustomFilter': {
Expand Down
11 changes: 6 additions & 5 deletions Extension/lib/filter/antibanner.js
Expand Up @@ -1691,13 +1691,14 @@ adguard.filters = (function (adguard) {
return;
}

adguard.subscriptions.getCustomFilterInfo(url, options, (filterData) => {
if (filterData) {
adguard.subscriptions.getCustomFilterInfo(url, options, (result = {}) => {
const { error, filter } = result;
if (filter) {
adguard.console.info('Custom filter data downloaded');
successCallback(filterData);
} else {
errorCallback();
successCallback(filter);
return;
}
errorCallback(error);
});
};

Expand Down
4 changes: 2 additions & 2 deletions Extension/lib/filter/subscription.js
Expand Up @@ -476,7 +476,7 @@ adguard.subscriptions = (function (adguard) {
});

if (filter) {
callback();
callback({ error: adguard.i18n.getMessage('options_antibanner_custom_filter_already_exists') });
return;
}

Expand All @@ -499,7 +499,7 @@ adguard.subscriptions = (function (adguard) {
filter.customUrl = url;
filter.rulesCount = rulesCount;

callback(filter);
callback({ filter });
}, function (cause) {
adguard.console.error(`Error download filter by url ${url}, cause: ${cause || ''}`);
callback();
Expand Down
23 changes: 18 additions & 5 deletions Extension/lib/pages/options.js
Expand Up @@ -1389,6 +1389,16 @@ var AntiBannerFilters = function (options) {
handleElTextContent(document.querySelector('#custom-filter-popup-added-url'), filter.customUrl, filter.customUrl);
}

function fillErrorMessage(error) {
const errorMessageNode = document.querySelector('.custom-filter-error-message');
if (error) {
errorMessageNode.textContent = error;
} else {
// Set default error message
errorMessageNode.textContent = i18n.getMessage('options_popup_check_false_description');
}
}

const makeSurePopupIsActive = () => {
if (!customFilterPopup.classList.contains('option-popup--active')) {
customFilterPopup.classList.add('option-popup--active');
Expand All @@ -1413,9 +1423,10 @@ var AntiBannerFilters = function (options) {
}

// Error window step
function renderStepThree() {
function renderStepThree(error) {
prepareRendering();
thirdStep.classList.add(POPUP_ACTIVE_CLASS);
fillErrorMessage(error);
}

function renderStepFour(filter) {
Expand All @@ -1432,11 +1443,12 @@ var AntiBannerFilters = function (options) {

const searchInputValue = searchInput.value && searchInput.value.trim();

contentPage.sendMessage({ type: 'loadCustomFilterInfo', url: searchInputValue }, function (filter) {
contentPage.sendMessage({ type: 'loadCustomFilterInfo', url: searchInputValue }, function (result) {
const { filter, error } = result;
if (filter) {
renderStepFour(filter);
} else {
renderStepThree();
renderStepThree(error);
}
});

Expand Down Expand Up @@ -1484,11 +1496,12 @@ var AntiBannerFilters = function (options) {
customFilterPopup.classList.add('option-popup--active');

if (isFilterSubscription) {
contentPage.sendMessage({ type: 'loadCustomFilterInfo', url, title }, function (filter) {
contentPage.sendMessage({ type: 'loadCustomFilterInfo', url, title }, function (result) {
const { filter, error } = result;
if (filter) {
renderStepFour(filter);
} else {
renderStepThree();
renderStepThree(error);
}
});
renderStepTwo();
Expand Down
2 changes: 1 addition & 1 deletion Extension/pages/options.html
Expand Up @@ -212,7 +212,7 @@
<div class="option-popup__subtitle"
i18n="options_popup_check_false_title">
</div>
<div class="option-popup__desc option-popup__desc--false option-popup__desc--tac"
<div class="custom-filter-error-message option-popup__desc option-popup__desc--false option-popup__desc--tac"
i18n="options_popup_check_false_description">
</div>
</div>
Expand Down

0 comments on commit 1ce4ede

Please sign in to comment.