mirror of
https://github.com/bitwarden/browser
synced 2025-12-14 07:13:32 +00:00
include downloader script and page
This commit is contained in:
26
src/content/downloader.ts
Normal file
26
src/content/downloader.ts
Normal 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);
|
||||
});
|
||||
@@ -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
|
||||
});
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user