From ac967ace5ea2266f07fdfb02667dad55edde2dc6 Mon Sep 17 00:00:00 2001 From: Jeremy Schomery Date: Wed, 8 Mar 2017 11:43:35 +0330 Subject: [PATCH] fixes https://github.com/schomery/stylish-chrome/issues/13#issuecomment-284582600 --- backup/fileSaveLoad.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/backup/fileSaveLoad.js b/backup/fileSaveLoad.js index b65ae2a7..0f481ee4 100644 --- a/backup/fileSaveLoad.js +++ b/backup/fileSaveLoad.js @@ -3,7 +3,7 @@ var STYLISH_DUMP_FILE_EXT = '.txt'; var STYLISH_DUMPFILE_EXTENSION = '.json'; -var STYLISH_DEFAULT_SAVE_NAME = 'stylus-mm-dd-yyy' + STYLISH_DUMP_FILE_EXT; +var STYLISH_DEFAULT_SAVE_NAME = 'stylus-mm-dd-yyyy' + STYLISH_DUMP_FILE_EXT; /** * !!works only when page has representation - backgound page won't work @@ -58,10 +58,16 @@ document.getElementById('file-all-styles').addEventListener('click', function () 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')); + let url = 'data:text/plain;charset=utf-8,' + encodeURIComponent(text); + // for long URLs; https://github.com/schomery/stylish-chrome/issues/13#issuecomment-284582600 + fetch(url) + .then(res => res.blob()) + .then(blob => { + let a = document.createElement('a'); + a.setAttribute('download', fileName); + a.setAttribute('href', URL.createObjectURL(blob)); + a.dispatchEvent(new MouseEvent('click')); + }); }); });