Scope site connection permissions per address
Some checks failed
check / check (push) Has been cancelled

allowedSites and deniedSites are now objects keyed by address instead
of flat arrays, so approving a site for one address no longer grants
access for all addresses. Old flat-array data is discarded on load.
Settings view collects unique hostnames across all addresses and
deleting removes the site from every address.
This commit is contained in:
2026-02-26 03:54:52 +07:00
parent 21ccecab46
commit 980fdda694
3 changed files with 51 additions and 22 deletions

View File

@@ -6,25 +6,31 @@ const { log } = require("../../shared/log");
const runtime =
typeof browser !== "undefined" ? browser.runtime : chrome.runtime;
function renderSiteList(containerId, list, stateKey) {
function renderSiteList(containerId, siteMap, stateKey) {
const container = $(containerId);
if (list.length === 0) {
const hostnames = [...new Set(Object.values(siteMap).flat())];
if (hostnames.length === 0) {
container.innerHTML = '<p class="text-xs text-muted">None</p>';
return;
}
let html = "";
list.forEach((hostname, i) => {
hostnames.forEach((hostname) => {
html += `<div class="flex justify-between items-center text-xs py-1 border-b border-border-light">`;
html += `<span>${hostname}</span>`;
html += `<button class="btn-remove-site border border-border px-1 hover:bg-fg hover:text-bg cursor-pointer" data-key="${stateKey}" data-index="${i}">[x]</button>`;
html += `<button class="btn-remove-site border border-border px-1 hover:bg-fg hover:text-bg cursor-pointer" data-key="${stateKey}" data-hostname="${hostname}">[x]</button>`;
html += `</div>`;
});
container.innerHTML = html;
container.querySelectorAll(".btn-remove-site").forEach((btn) => {
btn.addEventListener("click", async () => {
const key = btn.dataset.key;
const idx = parseInt(btn.dataset.index, 10);
state[key].splice(idx, 1);
const host = btn.dataset.hostname;
for (const addr of Object.keys(state[key])) {
state[key][addr] = state[key][addr].filter((h) => h !== host);
if (state[key][addr].length === 0) {
delete state[key][addr];
}
}
await saveState();
runtime.sendMessage({ type: "AUTISTMASK_REMOVE_SITE" });
renderSiteList(containerId, state[key], key);