options page and selector
parent
b8252e54b1
commit
e7e73b3460
@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Parse Policies - Options</title>
|
||||
<link rel="stylesheet" href="options.css" />
|
||||
<script src="options.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Parse Policies - Options</h1>
|
||||
<ul id="categories">
|
||||
<li class="category reference">
|
||||
<label for=""></label>
|
||||
<input type="checkbox" name="" id="" />
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,40 @@
|
||||
chrome.storage.sync.get(["categories", "selected"], (result) => {
|
||||
listAllCategories(result.categories, result.selected);
|
||||
});
|
||||
|
||||
function listAllCategories(categories, selected) {
|
||||
const list = document.querySelector("#categories");
|
||||
let reference = list.querySelector(".reference");
|
||||
for (const category in categories) {
|
||||
let item = reference.cloneNode(true);
|
||||
item.classList.remove("reference");
|
||||
|
||||
let label = item.querySelector("label");
|
||||
|
||||
label.innerHTML = categories[category].title;
|
||||
label.setAttribute("for", category);
|
||||
|
||||
let checkbox = item.querySelector("input");
|
||||
checkbox.checked = selected.includes(category);
|
||||
checkbox.setAttribute("name", category);
|
||||
|
||||
checkbox.addEventListener("change", () => {
|
||||
checkbox.checked
|
||||
? selected.push(category)
|
||||
: selected.splice(selected.indexOf(category), 1);
|
||||
chrome.storage.sync.set({ selected });
|
||||
});
|
||||
|
||||
list.appendChild(item);
|
||||
}
|
||||
}
|
||||
|
||||
function addOrRemove(array, value) {
|
||||
var index = array.indexOf(value);
|
||||
|
||||
if (index === -1) {
|
||||
array.push(value);
|
||||
} else {
|
||||
array.splice(index, 1);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue