This commit is contained in:
gorhill 2015-12-07 08:59:22 -05:00
parent eee7c29abe
commit fd1ccebf41
3 changed files with 14 additions and 3 deletions

View File

@ -143,17 +143,22 @@ var exportUserFiltersToFile = function() {
/******************************************************************************/
var applyChanges = function() {
var textarea = uDom.nodeFromId('userFilters');
var onWritten = function(details) {
if ( details.error ) {
return;
}
textarea.value = details.content;
cachedUserFilters = details.content.trim();
userFiltersChanged();
allFiltersApplyHandler();
textarea.focus();
};
var request = {
what: 'writeUserFilters',
content: uDom('#userFilters').val()
content: textarea.value
};
messager.send(request, onWritten);
};

View File

@ -862,10 +862,10 @@ var onMessage = function(request, sender, callback) {
// Async
switch ( request.what ) {
case 'readUserFilters':
return µb.assets.get(µb.userFiltersPath, callback);
return µb.loadUserFilters(callback);
case 'writeUserFilters':
return µb.assets.put(µb.userFiltersPath, request.content, callback);
return µb.saveUserFilters(request.content, callback);
default:
break;

View File

@ -151,6 +151,12 @@
/******************************************************************************/
µBlock.saveUserFilters = function(content, callback) {
// https://github.com/gorhill/uBlock/issues/1022
// Be sure to end with an empty line.
content = content.trim();
if ( content !== '' ) {
content += '\n';
}
this.assets.put(this.userFiltersPath, content, callback);
};