-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
46 lines (39 loc) · 1.23 KB
/
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* eslint-disable no-console */
const { log } = console;
function runInGradeTab(callback) {
const queryOptions = {
active: true,
currentWindow: true,
url: 'https://banner.apps.uillinois.edu/FacultySelfService/ssb/GradeEntry*',
windowType: 'normal',
};
chrome.tabs.query(queryOptions).then((result) => (result[0] ? callback(result[0].id) : console.log("This is not a final grade-entry page")));
}
function handleUIRequest(message) {
const { action, data } = message;
if (action !== 'gradehelper') {
log(`Unknown uiRequest ${action}`);
return;
}
const perform = (tabid) => {
if (tabid === undefined) {
return;
}
chrome.scripting.executeScript({
target: { tabId: tabid },
files: ['/gradehelper.js'],
}).then(() => {
chrome.tabs.sendMessage(tabid, { gradedata: data });
});
};
runInGradeTab(perform);
}
// eslint-disable-next-line no-unused-vars
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (chrome.runtime.id !== sender.id) {
log(`Ignoring message from ${sender.id}`);
return;
}
handleUIRequest(message);
return;
});