-
Notifications
You must be signed in to change notification settings - Fork 0
/
calendar.js
27 lines (22 loc) · 904 Bytes
/
calendar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
document.body.style.border = "5px solid red";
/* When the generator sent back the file, store it
* in a blob and download it to the user's PC: */
function download(file) {
console.log(file["file"]);
var blob = new Blob([file["file"]], {type : 'text/plain'});
var objectURL = URL.createObjectURL(blob);
browser.downloads.download({filename: file["filename"] + ".ics", url: objectURL});
}
/* When the extension button is clicked, the tab URL
* is checked to make sure we're on a DkIT timetable.
* If that's the case, the generate script is called.*/
browser.browserAction.onClicked.addListener((tab) => {
// Launch the script only when we're on a timetable page:
if (tab.url.includes("timetables.dkit.ie")) {
browser.tabs.executeScript({
file: "/generate.js"
});
// Listen for the generator's response:
browser.runtime.onMessage.addListener(download);
}
});