forked from See-Y/blackboard-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
27 lines (25 loc) · 946 Bytes
/
background.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
/**
* Go to course's collaborate page.
* @param {string} course_id course id
*/
function gotoCollaborate(course_id) {
var optionsUrl = `https://blackboard.unist.ac.kr/webapps/collab-ultra/tool/collabultra/lti/launch?course_id=${course_id}`
chrome.tabs.query({ url: optionsUrl }, function(tabs) {
if (tabs.length) {
chrome.tabs.create(tabs[0].id, { active: true });
} else {
chrome.tabs.create({ url: optionsUrl });
}
});
}
// Execute gotoCollaborate when alarm works.
chrome.alarms.onAlarm.addListener(function(alarm) {
console.log(alarm.name.split(":")[0] + " alarm works");
gotoCollaborate(alarm.name.split(":")[0]);
});
chrome.alarms.getAll(function(alarms) { console.log(alarms); })
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.sender === "downloader") chrome.downloads.download({url: request.url});
}
);