This commit is contained in:
parent
fb45e86648
commit
ac967ace5e
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
var STYLISH_DUMP_FILE_EXT = '.txt';
|
var STYLISH_DUMP_FILE_EXT = '.txt';
|
||||||
var STYLISH_DUMPFILE_EXTENSION = '.json';
|
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
|
* !!works only when page has representation - backgound page won't work
|
||||||
|
@ -58,12 +58,18 @@ document.getElementById('file-all-styles').addEventListener('click', function ()
|
||||||
let text = JSON.stringify(styles);
|
let text = JSON.stringify(styles);
|
||||||
let fileName = generateFileName() || STYLISH_DEFAULT_SAVE_NAME;
|
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');
|
let a = document.createElement('a');
|
||||||
a.href = 'data:text/plain;charset=utf-8,' + encodeURIComponent(text);
|
|
||||||
a.setAttribute('download', fileName);
|
a.setAttribute('download', fileName);
|
||||||
|
a.setAttribute('href', URL.createObjectURL(blob));
|
||||||
a.dispatchEvent(new MouseEvent('click'));
|
a.dispatchEvent(new MouseEvent('click'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById('unfile-all-styles').addEventListener('click', function () {
|
document.getElementById('unfile-all-styles').addEventListener('click', function () {
|
||||||
loadFromFile(STYLISH_DUMPFILE_EXTENSION).then(function (rawText) {
|
loadFromFile(STYLISH_DUMPFILE_EXTENSION).then(function (rawText) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user