export: create blob directly

fixes #211
This commit is contained in:
tophf 2017-10-14 04:25:46 +03:00
parent 0b17c669de
commit 721dfc4787
3 changed files with 27 additions and 35 deletions

View File

@ -37,7 +37,6 @@ globals:
saveStyleSafe: false
sessionStorageHash: false
download: false
doTimeout: false
invokeOrPostpone: false
# localization.js
template: false

View File

@ -383,13 +383,6 @@ function download(url) {
}
function doTimeout(ms = 0, ...args) {
return ms > 0
? () => new Promise(resolve => setTimeout(resolve, ms, ...args))
: new Promise(resolve => setTimeout(resolve, 0, ...args));
}
function invokeOrPostpone(isInvoke, fn, ...args) {
return isInvoke
? fn(...args)

View File

@ -306,12 +306,7 @@ function importFromString(jsonString) {
$('#file-all-styles').onclick = () => {
getStylesSafe().then(styles => {
const text = JSON.stringify(styles, null, '\t');
const url = 'data:text/plain;charset=utf-8,' + encodeURIComponent(text);
return url;
// for long URLs; https://github.com/schomery/stylus/issues/13#issuecomment-284582600
}).then(fetch)
.then(res => res.blob())
.then(blob => {
const blob = new Blob([text], {type : 'application/json'});
const objectURL = URL.createObjectURL(blob);
let link = $element({
tag:'a',
@ -328,13 +323,14 @@ $('#file-all-styles').onclick = () => {
tag: 'iframe',
style: 'width: 0; height: 0; position: fixed; opacity: 0;'.replace(/;/g, '!important;'),
}));
doTimeout().then(() => {
doTimeout()
.then(() => {
link = iframe.contentDocument.importNode(link, true);
iframe.contentDocument.body.appendChild(link);
})
.then(doTimeout)
.then(() => doTimeout())
.then(() => link.dispatchEvent(new MouseEvent('click')))
.then(doTimeout(1000))
.then(() => doTimeout(1000))
.then(() => {
URL.revokeObjectURL(objectURL);
iframe.remove();
@ -342,6 +338,10 @@ $('#file-all-styles').onclick = () => {
}
});
function doTimeout(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function generateFileName() {
const today = new Date();
const dd = ('0' + today.getDate()).substr(-2);