-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
62 lines (57 loc) · 2.02 KB
/
content.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
50
51
52
53
54
55
56
57
58
59
60
61
62
$(document).ready(function () {
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === "CREATE_CARD") {
chrome.storage.sync.set({ message }, function () {
showNewCard();
});
} else if (message.action === "REMOVE_CARD") {
$("#newCardFrame").remove();
} else if (message.action === "START_SESSION") {
startNewSession();
} else if (message.action === "END_SESSION") {
$("#sessionFrame").remove();
} else if (message.action === "GET_CARDS") {
chrome.storage.sync.get(["cards"], function (result) {
if (result && result.cards) {
sendResponse(result.cards);
} else sendResponse([]);
});
}
return true;
});
function showNewCard() {
let iFrame = document.createElement("iframe");
iFrame.src = chrome.runtime.getURL("html/newCardModal.html");
iFrame.id = "newCardFrame";
iFrame.style.height = "400px";
iFrame.style.width = "420px";
iFrame.style.position = "fixed";
iFrame.style.margin = "auto";
iFrame.style.zIndex = 9999;
iFrame.style.borderWidth = 0;
iFrame.style.borderRadius = "8px";
iFrame.style.top = "0";
iFrame.style.left = "0";
iFrame.style.right = "0";
iFrame.style.bottom = "0";
iFrame.setAttribute("align", "middle");
document.body.insertBefore(iFrame, document.body.firstChild);
}
function startNewSession() {
let iFrame = document.createElement("iframe");
iFrame.src = chrome.runtime.getURL("html/session.html");
iFrame.id = "sessionFrame";
iFrame.style.height = "100vh";
iFrame.style.width = "100%";
iFrame.style.position = "fixed";
iFrame.style.display = "flex";
iFrame.style.justifyContent = "center";
iFrame.style.alignItems = "center";
iFrame.style.backgroundColor = "#E0EAF4";
iFrame.style.opacity = 0.98;
iFrame.style.zIndex = 9999;
iFrame.setAttribute("align", "middle");
iFrame.style.margin = "auto";
document.body.insertBefore(iFrame, document.body.firstChild);
}
});