From 4b9fc6d6f5b8c42a7b7e700b076a93d355c4f32c Mon Sep 17 00:00:00 2001 From: gorhill Date: Tue, 6 Jan 2015 12:14:37 -0500 Subject: [PATCH] fixed import/export of dynamic rules --- src/_locales/en/messages.json | 14 +++++++------- src/js/dyna-rules.js | 20 +++++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 3f58f4fc2..77d4f2a4c 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -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...", diff --git a/src/js/dyna-rules.js b/src/js/dyna-rules.js index 52370b204..7c11fc5e0 100644 --- a/src/js/dyna-rules.js +++ b/src/js/dyna-rules.js @@ -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 }); }