forked from DrHazemAli/fb-guardian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
53 lines (46 loc) · 1.61 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
50
51
52
53
// popup.js
document.addEventListener("DOMContentLoaded", () => {
const apiKeyInput = document.getElementById("apiKey");
const keywordsInput = document.getElementById("keywords");
const saveBtn = document.getElementById("saveBtn");
// Radio buttons for blocking mode
const blockingModeRadios = document.querySelectorAll('input[name="blockingMode"]');
// Load existing configs
chrome.storage.sync.get(["openaiApiKey", "customKeywords", "blockingMode"], (result) => {
if (result.openaiApiKey) {
apiKeyInput.value = result.openaiApiKey;
}
if (result.customKeywords && result.customKeywords.length > 0) {
keywordsInput.value = result.customKeywords.join(", ");
}
if (result.blockingMode) {
// Check the correct radio
blockingModeRadios.forEach((radio) => {
radio.checked = (radio.value === result.blockingMode);
});
}
});
// Save new configs
saveBtn.addEventListener("click", () => {
const key = apiKeyInput.value.trim();
const keywords = keywordsInput.value
.split(",")
.map((kw) => kw.trim())
.filter((kw) => kw.length > 0);
// Read which blocking mode is selected
let selectedMode = "manual";
blockingModeRadios.forEach((radio) => {
if (radio.checked) {
selectedMode = radio.value;
}
});
// Store in chrome storage
chrome.storage.sync.set({
openaiApiKey: key,
customKeywords: keywords,
blockingMode: selectedMode
}, () => {
alert("Settings Saved.");
});
});
});