-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
49 lines (45 loc) · 1.75 KB
/
popup.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
let toggleExtension = document.getElementById("toggleExtension");
let enterNameTextBox = document.getElementById("enterNameTextBox");
chrome.storage.sync.get(null, (resp) => {
toggleExtension.checked = resp.isExtensionEnabled;
enterNameTextBox.value = resp.nameToCheck.toLowerCase();
console.log("updated details from storage")
});
function isValidName(name) {
if (name && name.trim())
return true;
else
return false;
}
toggleExtension.addEventListener("change", async () => {
if (toggleExtension.checked && !isValidName(enterNameTextBox.value)) {
document.getElementById("extraInfo").style.visibility = "visible";
toggleExtension.checked = false;
} else {
document.getElementById("extraInfo").style.visibility = "hidden";
return chrome.storage.sync.set({ "isExtensionEnabled": (toggleExtension.checked), "nameToCheck": enterNameTextBox.value }, myCheckfunc);
}
});
async function myCheckfunc() {
if (toggleExtension.checked) {
chrome.tabs.query({ active: true, currentWindow: true }, function (mytab) {
chrome.tabs.sendMessage(mytab[0].id, { greeting: "startCheckingName" }, function (response) {
try {
console.log(response.farewell);
} catch (err) {
console.log(err);
}
});
});
} else {
chrome.tabs.query({ active: true, currentWindow: true }, function (mytab) {
chrome.tabs.sendMessage(mytab[0].id, { greeting: "stopCheckingName" }, function (response) {
try {
console.log(response.farewell);
} catch (err) {
console.log(err);
}
});
});
}
}