Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "Download All" for Safari #5910

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions src/scripts/multiDownload.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,25 @@ function fallback(urls) {
})();
}

function sameDomain(url) {
const a = document.createElement('a');
a.href = url;

return window.location.hostname === a.hostname && window.location.protocol === a.protocol;
}

function download(url) {
const a = document.createElement('a');
a.download = '';
a.href = url;
// firefox doesn't support `a.click()`...
a.dispatchEvent(new MouseEvent('click'));
a.click();
}

export default function (urls) {
if (!urls) {
throw new Error('`urls` required');
}

if (typeof document.createElement('a').download === 'undefined') {
if (typeof document.createElement('a').download === 'undefined' || browser.iOS) {
return fallback(urls);
}

let delay = 0;

urls.forEach(function (url) {
// the download init has to be sequential for firefox if the urls are not on the same domain
if (browser.firefox && !sameDomain(url)) {
setTimeout(download.bind(null, url), 100 * ++delay);
return;
}

download(url);
setTimeout(download.bind(null, url), 100 * ++delay);
});
}
Loading