Jeremy Schomery 2017-03-08 11:43:35 +03:30
parent fb45e86648
commit ac967ace5e

View File

@ -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,11 +58,17 @@ document.getElementById('file-all-styles').addEventListener('click', function ()
let text = JSON.stringify(styles);
let fileName = generateFileName() || STYLISH_DEFAULT_SAVE_NAME;
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.href = 'data:text/plain;charset=utf-8,' + encodeURIComponent(text);
a.setAttribute('download', fileName);
a.setAttribute('href', URL.createObjectURL(blob));
a.dispatchEvent(new MouseEvent('click'));
});
});
});
document.getElementById('unfile-all-styles').addEventListener('click', function () {