From 139e4791b2ac7ecab05454cc339ce2035f04aaca Mon Sep 17 00:00:00 2001 From: James Chuong Date: Sat, 29 Jun 2024 18:33:20 -0700 Subject: [PATCH 1/3] Fix download all for Safari Added check to use fallback downloader for iOS Added check for safari to use the delayed download function Remove old comment about firefox, as a.click() supported since Firefox 75 (2020) Fixes: #5672 --- src/scripts/multiDownload.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/scripts/multiDownload.js b/src/scripts/multiDownload.js index ec3db52015f..5569c19d17b 100644 --- a/src/scripts/multiDownload.js +++ b/src/scripts/multiDownload.js @@ -38,8 +38,7 @@ 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) { @@ -47,7 +46,8 @@ export default function (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); } @@ -55,7 +55,9 @@ export default function (urls) { 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)) { + // desktop safari also requires the delay + if ((browser.firefox && !sameDomain(url)) + || browser.safari) { setTimeout(download.bind(null, url), 100 * ++delay); return; } From 9354f1fdb65adb1478f62efbb4e6416b448c437b Mon Sep 17 00:00:00 2001 From: James Chuong Date: Mon, 12 Aug 2024 20:24:48 -0700 Subject: [PATCH 2/3] Change download to always use setTimeout Instead of conditionally using setTimeout based on browser, we should always use it since it sometimes also misses some episodes. --- src/scripts/multiDownload.js | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/scripts/multiDownload.js b/src/scripts/multiDownload.js index 5569c19d17b..ae85d58e1fe 100644 --- a/src/scripts/multiDownload.js +++ b/src/scripts/multiDownload.js @@ -27,13 +27,6 @@ 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 = ''; @@ -54,14 +47,6 @@ export default function (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 - // desktop safari also requires the delay - if ((browser.firefox && !sameDomain(url)) - || browser.safari) { - setTimeout(download.bind(null, url), 100 * ++delay); - return; - } - - download(url); + setTimeout(download.bind(null, url), 100 * ++delay); }); } From e23904cae2d913dd0b07e862e314c137010b9af6 Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Tue, 13 Aug 2024 11:20:39 -0400 Subject: [PATCH 3/3] Update formatting --- src/scripts/multiDownload.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/scripts/multiDownload.js b/src/scripts/multiDownload.js index ae85d58e1fe..c9f40f56a42 100644 --- a/src/scripts/multiDownload.js +++ b/src/scripts/multiDownload.js @@ -39,8 +39,7 @@ export default function (urls) { throw new Error('`urls` required'); } - if (typeof document.createElement('a').download === 'undefined' - || browser.iOS) { + if (typeof document.createElement('a').download === 'undefined' || browser.iOS) { return fallback(urls); }