-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
51 lines (43 loc) · 1.37 KB
/
extension.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
let twitchUsername = "";
const userNameInput = document.querySelector("#userName--input");
const submitBtn = document.querySelector("#btn--submit");
userNameInput.addEventListener("input", (e) => {
twitchUsername = e.target.value;
if (e.target.value) {
submitBtn.removeAttribute("disabled");
} else {
submitBtn.addAttribute("disabled");
}
});
submitBtn.addEventListener("click", async (e) => {
document.querySelector(
"#selected--username"
).innerHTML = `@${twitchUsername}`;
chrome.storage.local
.set({ twitchMessageUser: twitchUsername })
.then(async () => {
const [tab] = await chrome.tabs.query({
active: true,
lastFocusedWindow: true,
});
const response = await chrome.tabs.sendMessage(tab.id, {
greeting: "hello",
name: twitchUsername,
});
});
// do something with response here, not outside the function
// console.log(response);
});
// check if username has already been selected
chrome.storage.local.get(["twitchMessageUser"]).then(async (result) => {
document.querySelector(
"#selected--username"
).innerHTML = `@${result?.twitchMessageUser}`;
});
chrome.storage.local.get(["twitchMessages"]).then(async (result) => {
if (result?.twitchMessages) {
document.querySelector("#cmessage").innerHTML = `popop@${JSON.stringify({
msg: result?.twitchMessages,
})}`;
}
});