var getFilenameFromURL = function (url) { return url.split('/').pop(); };
var isAbsoluteUrl = function (url) { return url.indexOf('://') > 0 || url.indexOf('//') === 0; };
var isExternalUrl = function (url) {
    if (!isAbsoluteUrl(url))
        return false;
    var urlParts = new URL(url);
    return urlParts.host !== location.host;
};
var REMOVE_IFRAME_DELAY = 30000;
export var downloadImagesByURLs = function (urls) {
    urls.forEach(function (url, index) {
        try {
            if (isExternalUrl(url)) {
                var iframe_1 = document.createElement('iframe');
                iframe_1.setAttribute('style', 'display: none;');
                iframe_1.setAttribute('src', url);
                document.body.appendChild(iframe_1);
                setTimeout(function () { return document.body.removeChild(iframe_1); }, (index + 1) * REMOVE_IFRAME_DELAY);
            }
            else {
                var link = document.createElement('a');
                link.href = url;
                link.download = getFilenameFromURL(url);
                document.body.appendChild(link);
                link.click();
                document.body.removeChild(link);
            }
        }
        catch (e) {
            console.error(e);
        }
    });
};
