From fb45e86648a9db3b0cd0ba42e6f983e1c03eb7ce Mon Sep 17 00:00:00 2001 From: Jeremy Schomery Date: Mon, 6 Mar 2017 18:14:20 +0330 Subject: [PATCH] fixes #13 --- backup/fileSaveLoad.js | 29 ++++++++--------------------- manifest.json | 3 --- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/backup/fileSaveLoad.js b/backup/fileSaveLoad.js index b06becd5..b65ae2a7 100644 --- a/backup/fileSaveLoad.js +++ b/backup/fileSaveLoad.js @@ -5,20 +5,6 @@ var STYLISH_DUMP_FILE_EXT = '.txt'; var STYLISH_DUMPFILE_EXTENSION = '.json'; var STYLISH_DEFAULT_SAVE_NAME = 'stylus-mm-dd-yyy' + STYLISH_DUMP_FILE_EXT; -function saveAsFile (text, fileName, dialog) { - fileName = fileName || STYLISH_DEFAULT_SAVE_NAME; - dialog = typeof dialog === 'boolean' ? dialog : true; - - return new Promise(function (resolve) { - var fileContent = 'data:text/plain;charset=utf-8,' + encodeURIComponent(text); - chrome.downloads.download({ - filename: fileName, - saveAs: true, - url: fileContent - }, resolve); - }); -} - /** * !!works only when page has representation - backgound page won't work * @@ -68,13 +54,14 @@ function generateFileName() { } document.getElementById('file-all-styles').addEventListener('click', function () { - chrome.permissions.request({permissions: ['downloads']}, function (granted) { - if (granted) { - getStyles({}, function (styles) { - var text = JSON.stringify(styles); - saveAsFile(text, generateFileName()); - }); - } + getStyles({}, function (styles) { + let text = JSON.stringify(styles); + let fileName = generateFileName() || STYLISH_DEFAULT_SAVE_NAME; + + let a = document.createElement('a'); + a.href = 'data:text/plain;charset=utf-8,' + encodeURIComponent(text); + a.setAttribute('download', fileName); + a.dispatchEvent(new MouseEvent('click')); }); }); diff --git a/manifest.json b/manifest.json index 001b60ce..66d902ea 100644 --- a/manifest.json +++ b/manifest.json @@ -18,9 +18,6 @@ "storage", "*://*/*" ], - "optional_permissions": [ - "downloads" - ], "background": { "scripts": ["messaging.js", "storage-websql.js", "storage.js", "background.js", "update.js"] },