restore downloader script

This commit is contained in:
Kyle Spearrin 2019-08-21 17:10:44 -04:00
parent eec577372c
commit 990b364ae1
1 changed files with 32 additions and 1 deletions

View File

@ -1,3 +1,34 @@
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
// TODO const isSafari = (typeof safari !== 'undefined') && navigator.userAgent.indexOf(' Safari/') !== -1 &&
navigator.userAgent.indexOf('Chrome') === -1;
if (!isSafari) {
return;
}
safari.self.addEventListener('message', (msgEvent: any) => {
// tslint:disable-next-line
console.log('GOT MESSAGE');
// tslint:disable-next-line
console.log(msgEvent);
doDownload(JSON.parse(msgEvent.message.msg));
}, false);
function doDownload(msg: any) {
if (msg.command === 'downloaderPageData' && msg.data) {
const blob = new Blob([msg.data.blobData], msg.data.blobOptions);
if (navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(blob, msg.data.fileName);
} else {
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = msg.data.fileName;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
}
window.setTimeout(() => window.close(), 1500);
}
}); });