61 lines
1.5 KiB
JavaScript
61 lines
1.5 KiB
JavaScript
const input = document.getElementById("channelInput");
|
|
const addBtn = document.getElementById("addBtn");
|
|
const list = document.getElementById("channelList");
|
|
const debugToggle = document.getElementById("debugToggle");
|
|
const resetBtn = document.getElementById("resetBtn");
|
|
|
|
const DEFAULTS = {
|
|
whitelist: [],
|
|
debug: false
|
|
};
|
|
|
|
function loadChannels() {
|
|
chrome.storage.local.get(DEFAULTS, ({ whitelist, debug }) => {
|
|
list.innerHTML = "";
|
|
debugToggle.checked = Boolean(debug);
|
|
whitelist.forEach((name, index) => {
|
|
const li = document.createElement("li");
|
|
li.textContent = name;
|
|
|
|
const remove = document.createElement("button");
|
|
remove.textContent = "x";
|
|
remove.onclick = () => removeChannel(index);
|
|
|
|
li.appendChild(remove);
|
|
list.appendChild(li);
|
|
});
|
|
});
|
|
}
|
|
|
|
function addChannel() {
|
|
const name = input.value.trim();
|
|
if (!name) return;
|
|
|
|
chrome.storage.local.get(DEFAULTS, ({ whitelist }) => {
|
|
whitelist.push(name);
|
|
chrome.storage.local.set({ whitelist }, loadChannels);
|
|
});
|
|
|
|
input.value = "";
|
|
}
|
|
|
|
function removeChannel(index) {
|
|
chrome.storage.local.get(DEFAULTS, ({ whitelist }) => {
|
|
whitelist.splice(index, 1);
|
|
chrome.storage.local.set({ whitelist }, loadChannels);
|
|
});
|
|
}
|
|
|
|
function setDebug(enabled) {
|
|
chrome.storage.local.set({ debug: Boolean(enabled) });
|
|
}
|
|
|
|
function resetDefaults() {
|
|
chrome.storage.local.set(DEFAULTS, loadChannels);
|
|
}
|
|
|
|
addBtn.onclick = addChannel;
|
|
debugToggle.onchange = e => setDebug(e.target.checked);
|
|
resetBtn.onclick = resetDefaults;
|
|
loadChannels();
|