diff --git a/.eslintrc b/.eslintrc index 8256da07..077ef42c 100644 --- a/.eslintrc +++ b/.eslintrc @@ -37,6 +37,7 @@ globals: saveStyleSafe: false sessionStorageHash: false download: false + doTimeout: false # localization.js template: false t: false diff --git a/backup/fileSaveLoad.js b/backup/fileSaveLoad.js index 5bf027a5..e8fd7de4 100644 --- a/backup/fileSaveLoad.js +++ b/backup/fileSaveLoad.js @@ -329,14 +329,16 @@ $('#file-all-styles').onclick = () => { tag: 'iframe', style: 'width: 0; height: 0; position: fixed; opacity: 0;'.replace(/;/g, '!important;'), })); - setTimeout(() => { + doTimeout().then(() => { link = iframe.contentDocument.importNode(link, true); iframe.contentDocument.body.appendChild(link); - link.dispatchEvent(new MouseEvent('click')); - setTimeout(() => { - URL.revokeObjectURL(objectURL); - iframe.remove(); - }, 1000); + }) + .then(doTimeout) + .then(() => link.dispatchEvent(new MouseEvent('click'))) + .then(doTimeout(1000)) + .then(() => { + URL.revokeObjectURL(objectURL); + iframe.remove(); }); } }); diff --git a/messaging.js b/messaging.js index cdee9fe0..f7ffeea6 100644 --- a/messaging.js +++ b/messaging.js @@ -359,3 +359,10 @@ function download(url) { xhr.send(query); }); } + + +function doTimeout(ms = 0, ...args) { + return ms > 0 + ? () => new Promise(resolve => setTimeout(resolve, ms, ...args)) + : new Promise(resolve => setTimeout(resolve, 0, ...args)); +}