1
Fork 0
mirror of https://github.com/Steffo99/bbdl-firefox.git synced 2024-11-21 23:24:18 +00:00
bbdl-firefox/extension/background.js
2020-09-23 15:05:18 +02:00

34 lines
No EOL
895 B
JavaScript

"use strict";
function onMessageReceived(message) {
console.debug("Received message from the content script")
if(message === null) {
console.warn("No link received from the content script.");
return
}
console.debug(`Starting download of ${message}`)
browser.downloads.download({
"url": message["download_url"]
}).then(() => {
console.info("Download complete!")
})
}
function onBrowserAction() {
console.debug("Browser action clicked")
browser.tabs.query({
currentWindow: true,
active: true
}).then((tabs) => {
for(const tab of tabs) {
browser.tabs.sendMessage(tab.id, {"download": true})
}
})
}
browser.pageAction.onClicked.addListener(onBrowserAction);
browser.runtime.onMessage.addListener(onMessageReceived);
console.debug("bbdl-background was loaded successfully!")