include downloader script and page

This commit is contained in:
Kyle Spearrin 2019-08-21 16:50:15 -04:00
parent 6af618cb41
commit eec577372c
5 changed files with 36 additions and 29 deletions

View File

@ -31,6 +31,9 @@ const filters = {
'!build/safari/**/*',
'!build/downloader/**/*'
],
safariDir: [
'!build/safari/**/*'
],
webExt: [
'!build/manifest.json'
],
@ -215,7 +218,7 @@ function safariAppCopyBuild(source, dest) {
return new Promise((resolve, reject) => {
gulp.src(source)
.on('error', reject)
.pipe(filter(['**'].concat(filters.edge).concat(filters.fonts).concat(filters.safari)
.pipe(filter(['**'].concat(filters.edge).concat(filters.fonts).concat(filters.safariDir)
.concat(filters.webExt).concat(filters.nonSafariApp)))
.pipe(gulp.dest(dest))
.on('end', resolve);

26
src/content/downloader.ts Normal file
View File

@ -0,0 +1,26 @@
document.addEventListener('DOMContentLoaded', (event) => {
const isSafari = (typeof safari !== 'undefined') && navigator.userAgent.indexOf(' Safari/') !== -1 &&
navigator.userAgent.indexOf('Chrome') === -1;
if (!isSafari) {
return;
}
safari.self.addEventListener('message', (msgEvent: any) => {
const msg = JSON.parse(msgEvent.message.msg);
if (msg.command === 'downloaderPageData') {
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);
}
}, false);
});

View File

@ -1,30 +1,3 @@
document.addEventListener('DOMContentLoaded', () => {
const isSafari = (typeof safari !== 'undefined') && navigator.userAgent.indexOf(' Safari/') !== -1 &&
navigator.userAgent.indexOf('Chrome') === -1;
if (!isSafari) {
return;
}
safari.self.addEventListener('message', (msgEvent: any) => {
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);
}
// TODO
});

View File

@ -53,6 +53,10 @@
<key>Script</key>
<string>app/content/shortcuts.js</string>
</dict>
<dict>
<key>Script</key>
<string>app/content/downloader.js</string>
</dict>
</array>
<key>SFSafariToolbarItem</key>
<dict>

View File

@ -145,6 +145,7 @@ const config = {
'background': './src/background.ts',
'content/autofill': './src/content/autofill.js',
'content/autofiller': './src/content/autofiller.ts',
'content/downloader': './src/content/downloader.ts',
'content/notificationBar': './src/content/notificationBar.ts',
'content/shortcuts': './src/content/shortcuts.ts',
'notification/bar': './src/notification/bar.js',