diff --git a/.eslintrc b/.eslintrc index 2e335468..5921b11d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -37,7 +37,6 @@ globals: saveStyleSafe: false sessionStorageHash: false download: false - doTimeout: false invokeOrPostpone: false # localization.js template: false diff --git a/js/messaging.js b/js/messaging.js index 432ba0fd..6d4a19a7 100644 --- a/js/messaging.js +++ b/js/messaging.js @@ -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) diff --git a/manage/fileSaveLoad.js b/manage/fileSaveLoad.js index 4a8397ec..bd6823b0 100644 --- a/manage/fileSaveLoad.js +++ b/manage/fileSaveLoad.js @@ -306,41 +306,41 @@ 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 objectURL = URL.createObjectURL(blob); - let link = $element({ - tag:'a', - href: objectURL, - type: 'application/json', - download: generateFileName(), - }); - // TODO: remove the fallback when FF multi-process bug is fixed - if (!FIREFOX) { - link.dispatchEvent(new MouseEvent('click')); - setTimeout(() => URL.revokeObjectURL(objectURL)); - } else { - const iframe = document.body.appendChild($element({ - tag: 'iframe', - style: 'width: 0; height: 0; position: fixed; opacity: 0;'.replace(/;/g, '!important;'), - })); - doTimeout().then(() => { + const blob = new Blob([text], {type : 'application/json'}); + const objectURL = URL.createObjectURL(blob); + let link = $element({ + tag:'a', + href: objectURL, + type: 'application/json', + download: generateFileName(), + }); + // TODO: remove the fallback when FF multi-process bug is fixed + if (!FIREFOX) { + link.dispatchEvent(new MouseEvent('click')); + setTimeout(() => URL.revokeObjectURL(objectURL)); + } else { + const iframe = document.body.appendChild($element({ + tag: 'iframe', + style: 'width: 0; height: 0; position: fixed; opacity: 0;'.replace(/;/g, '!important;'), + })); + 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(); }); - } - }); + } + }); + + function doTimeout(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } function generateFileName() { const today = new Date();