fixed import/export of dynamic rules

This commit is contained in:
gorhill 2015-01-06 12:14:37 -05:00
parent 5e8b540669
commit 4b9fc6d6f5
2 changed files with 18 additions and 16 deletions

View file

@ -320,8 +320,8 @@
"description":"English: Export"
},
"1pExportFilename" : {
"message": "ublock-custom-filters_{{datetime}}.txt",
"description": "English: ublock-custom-filters_{{datetime}}.txt"
"message": "my-ublock-static-filters_{{datetime}}.txt",
"description": "English: my-ublock-static-filters_{{datetime}}.txt"
},
"1pApplyChanges":{
"message":"Apply changes",
@ -348,7 +348,7 @@
"description": ""
},
"rulesDefaultFileName": {
"message": "my-ublock-dynamic-rules.txt",
"message": "my-ublock-dynamic-rules_{{datetime}}.txt",
"description": "default file name to use"
},
"whitelistPrompt":{
@ -364,8 +364,8 @@
"description":"English: Export"
},
"whitelistExportFilename" : {
"message": "ublock-whitelist_{{datetime}}.txt",
"description": "English: ublock-whitelist_{{datetime}}.txt"
"message": "my-ublock-whitelist_{{datetime}}.txt",
"description": "English: my-ublock-whitelist_{{datetime}}.txt"
},
"whitelistApply":{
"message":"Apply changes",
@ -432,8 +432,8 @@
"description": "English: Backup to file"
},
"aboutBackupFilename" : {
"message": "ublock-backup_{{datetime}}.txt",
"description": "English: ublock-backup_{{datetime}}.txt"
"message": "my-ublock-backup_{{datetime}}.txt",
"description": "English: my-ublock-backup_{{datetime}}.txt"
},
"aboutRestoreDataButton" : {
"message": "Restore from file...",

View file

@ -19,7 +19,7 @@
Home: https://github.com/gorhill/uMatrix
*/
/* global chrome, messaging, uDom */
/* global vAPI, uDom */
/******************************************************************************/
@ -97,11 +97,9 @@ function handleImportFilePicker() {
if ( typeof this.result !== 'string' || this.result === '' ) {
return;
}
var request = {
'what': 'setDynamicRules',
'rawRules': uDom('#rulesEditor').val()
};
messager.send(request, processRules);
var textarea = uDom('#rulesEditor');
textarea.val([textarea.val(), this.result].join('\n').trim());
rulesChanged();
};
var file = this.files[0];
if ( file === undefined || file.name === '' ) {
@ -129,9 +127,13 @@ var startImportFilePicker = function() {
/******************************************************************************/
function exportUserRulesToFile() {
chrome.downloads.download({
'url': 'data:text/plain,' + encodeURIComponent(rulesFromHTML('#diff .left li')),
'filename': uDom('[data-i18n="userRulesDefaultFileName"]').text(),
var now = new Date();
var filename = vAPI.i18n('rulesDefaultFileName')
.replace('{{datetime}}', now.toLocaleString())
.replace(/ +/g, '_');
vAPI.download({
'url': 'data:text/plain,' + encodeURIComponent(uDom('#rulesEditor').val()),
'filename': filename,
'saveAs': true
});
}