file picker is gone: generate a unique filename each time

This commit is contained in:
Raymond Hill 2014-11-29 16:04:34 -02:00
parent 3ba151e89d
commit 52e8cb5338
3 changed files with 29 additions and 24 deletions

View File

@ -20,12 +20,13 @@
*/
/* global vAPI, uDom */
'use strict';
/******************************************************************************/
(function() {
'use strict';
/******************************************************************************/
var cachedUserFilters = '';
@ -67,7 +68,7 @@ function allFiltersApplyHandler() {
/******************************************************************************/
function handleImportFilePicker() {
var handleImportFilePicker = function() {
var fileReaderOnLoadHandler = function() {
var textarea = uDom('#userFilters');
textarea.val([textarea.val(), this.result].join('\n').trim());
@ -83,7 +84,7 @@ function handleImportFilePicker() {
var fr = new FileReader();
fr.onload = fileReaderOnLoadHandler;
fr.readAsText(file);
}
};
/******************************************************************************/
@ -98,20 +99,21 @@ var startImportFilePicker = function() {
/******************************************************************************/
function exportUserFiltersToFile() {
var exportUserFiltersToFile = function() {
var val = uDom('#userFilters').val().trim();
if (val) {
vAPI.download({
'url': 'data:text/plain;charset=utf-8,' + encodeURIComponent(val),
'filename': 'my-ublock-filters.txt'
});
if ( val === '' ) {
return;
}
}
var now = new Date();
vAPI.download({
'url': 'data:text/plain;charset=utf-8,' + encodeURIComponent(val),
'filename': 'ublock-filters_' + now.toLocaleString().replace(/ +/g, '_') + '.txt'
});
};
/******************************************************************************/
function userFiltersApplyHandler() {
var userFiltersApplyHandler = function() {
var onWritten = function(details) {
if ( details.error ) {
return;
@ -125,7 +127,7 @@ function userFiltersApplyHandler() {
content: uDom('#userFilters').val()
};
messager.send(request, onWritten);
}
};
/******************************************************************************/

View File

@ -19,13 +19,14 @@
Home: https://github.com/gorhill/uBlock
*/
/* global µBlock, uDom */
'use strict';
/* global vAPI, uDom */
/******************************************************************************/
uDom.onLoad(function() {
'use strict';
/******************************************************************************/
var messager = vAPI.messaging.channel('about.js');
@ -37,10 +38,10 @@ var exportToFile = function() {
if (!userData) {
return;
}
var now = new Date();
vAPI.download({
'url': 'data:text/plain;charset=utf-8,' + encodeURIComponent(JSON.stringify(userData)),
'filename': 'ublock-backup.txt'
'filename': 'ublock-backup_' + now.toLocaleString().replace(/ +/g, '_') + '.txt'
});
};

View File

@ -20,12 +20,13 @@
*/
/* global vAPI, uDom */
'use strict';
/******************************************************************************/
(function() {
'use strict';
/******************************************************************************/
var messager = vAPI.messaging.channel('whitelist.js');
@ -94,13 +95,14 @@ var startImportFilePicker = function() {
var exportWhitelistToFile = function() {
var val = uDom('#whitelist').val().trim();
if (val) {
vAPI.download({
'url': 'data:text/plain;charset=utf-8,' + encodeURIComponent(val),
'filename': 'my-ublock-whitelist.txt'
});
if ( val === '' ) {
return;
}
var now = new Date();
vAPI.download({
'url': 'data:text/plain;charset=utf-8,' + encodeURIComponent(val),
'filename': 'ublock-whitelist_' + now.toLocaleString().replace(/ +/g, '_') + '.txt'
});
};
/******************************************************************************/