-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
79 lines (64 loc) · 2.86 KB
/
background.js
File metadata and controls
79 lines (64 loc) · 2.86 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
console.log("%cSBCL: Background setup begun", 'color:rgb(247, 255, 129)');
function clear() {
// Clears all chrome.storage.local contents for the extension
chrome.storage.local.clear();
iter_value = undefined;
}
function change_icon(path) {
chrome.browserAction.setIcon({ path: path });
}
chrome.storage.local.get("iterator", function(result) {
let iter_value = result.iterator;
chrome.management.getSelf(function(extensionInfo) {
let install = 'standard';
install = extensionInfo.installType; // Comment out for normal development
if (install === 'development') {
console.warn("SBCL: Development mode active"); // Shouldn't be error
console.log("%cSBCL: Clearing local storage...", 'color:rgb(247, 255, 129)');
clear(); // Remove in production
} else {
console.log("%cSBCL: Standard install detected", 'color:rgb(247, 255, 129)');
}
if (typeof iter_value === 'undefined' | iter_value == "[object Object]") {
console.warn("SBCL: Iterator undefined");
console.log("%cSBCL: Initiating setup...", 'color:rgb(247, 255, 129)');
const iterator = {
id: "iterator",
value: 0,
}
chrome.storage.local.set({ [iterator.id]: iterator }, () => {
console.warn("SBCL: Iterator not found. This is expected behaviour for initial setup or indicates a fault in local storage.");
});
iter_value = 0;
} else {
console.log("%cSBCL: Current iterator = " + iter_value, 'color:rgb(247, 255, 129)');
}
});
});
chrome.storage.local.get("homework_type", function(result) {
let type_value = result.homework_type;
if (typeof type_value === 'undefined' | type_value == "[object Object]") {
console.warn("SBCL: No previous homework type identified");
const type_to_save = {
id: "homework_type",
value: 8, // Never an acceptable value so clearly indicative of a fault
}
chrome.storage.local.set({ [type_to_save.id]: type_to_save }, () => {
console.log("%cSBCL: Saving default homework type", 'color:rgb(247, 255, 129)');
});
chrome.storage.local.get({ [type_to_save.id]: type_to_save}, () => {
console.log(type_to_save.value);
});
} else {
console.log("%cSBCL: Current homework type = " + type_value, 'color:rgb(247, 255, 129)');
}
});
// Listen for messages from content scripts
let retrieved_answers = [null];
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === "SEND_ANSWERS") {
retrieved_answers = message.data;
} else if (message.type === "GET_ANSWERS") {
sendResponse({ array: retrieved_answers });
}
});