-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
49 lines (43 loc) · 1.2 KB
/
app.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
47
48
49
// @ts-check
var flag = false;
chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
// If the received message has the expected format...
console.log("Content Script executed");
if (msg.text === "needDOM") {
// Call the specified callback, passing
// the web-page's DOM content as argument
document.addEventListener("mouseup", highlight, flag);
}
});
async function highlight() {
var text = document.getSelection().toString();
if (!text) return;
var re = /[A-Z][a-z]+/g;
var m;
var list = [];
while ((m = re.exec(text))) {
list.push(m[0]);
}
chrome.storage.sync.get(
{
school: ""
},
async function(items) {
let uni = items.school;
const school = uni.replace(" ", "+");
var key = list[0] + "+" + list[list.length - 1] + "+" + uni; // Add University
key = key.toLowerCase();
var value = await getAPI(key);
console.log(value);
chrome.runtime.sendMessage(
{ text: "gotData", data: JSON.stringify(value) },
function(response) {}
);
flag = false;
}
);
}
const getAPI = key =>
fetch(`https://primeval-rain-199602.appspot.com/${key}`).then(response =>
response.json()
);