chore: format and lint

This commit is contained in:
Ren Amamiya
2026-04-08 11:28:39 +07:00
parent 5b7b06ff5d
commit 387796faa3
26 changed files with 28646 additions and 25809 deletions

View File

@@ -22,21 +22,18 @@ function matchConditions(conditions, event) {
}
export async function getPermissionStatus(host, type, event) {
let {policies} = await browser.storage.local.get('policies')
const { policies } = await browser.storage.local.get('policies')
let answers = [true, false]
const answers = [true, false]
for (let i = 0; i < answers.length; i++) {
let accept = answers[i]
let {conditions} = policies?.[host]?.[accept]?.[type] || {}
const accept = answers[i]
const { conditions } = policies?.[host]?.[accept]?.[type] || {}
if (conditions) {
if (type === 'signEvent') {
if (matchConditions(conditions, event)) {
return accept // may be true or false
} else {
// if this doesn't match we just continue so it will either match for the opposite answer (reject)
// or it will end up returning undefined at the end
continue
}
} else {
return accept // may be true or false
@@ -48,17 +45,17 @@ export async function getPermissionStatus(host, type, event) {
}
export async function updatePermission(host, type, accept, conditions) {
let {policies = {}} = await browser.storage.local.get('policies')
const { policies = {} } = await browser.storage.local.get('policies')
// if the new conditions is "match everything", override the previous
if (Object.keys(conditions).length === 0) {
conditions = {}
} else {
// if we already had a policy for this, merge the conditions
let existingConditions = policies[host]?.[accept]?.[type]?.conditions
const existingConditions = policies[host]?.[accept]?.[type]?.conditions
if (existingConditions) {
if (existingConditions.kinds && conditions.kinds) {
Object.keys(existingConditions.kinds).forEach(kind => {
Object.keys(existingConditions.kinds).forEach((kind) => {
conditions.kinds[kind] = true
})
}
@@ -66,8 +63,8 @@ export async function updatePermission(host, type, accept, conditions) {
}
// if we have a reverse policy (accept / reject) that is exactly equal to this, remove it
let other = !accept
let reverse = policies?.[host]?.[other]?.[type]
const other = !accept
const reverse = policies?.[host]?.[other]?.[type]
if (
reverse &&
JSON.stringify(reverse.conditions) === JSON.stringify(conditions)
@@ -83,19 +80,19 @@ export async function updatePermission(host, type, accept, conditions) {
created_at: Math.round(Date.now() / 1000)
}
browser.storage.local.set({policies})
browser.storage.local.set({ policies })
}
export async function removePermissions(host, accept, type) {
let {policies = {}} = await browser.storage.local.get('policies')
const { policies = {} } = await browser.storage.local.get('policies')
delete policies[host]?.[accept]?.[type]
browser.storage.local.set({policies})
browser.storage.local.set({ policies })
}
export async function showNotification(host, answer, type, params) {
let ok = await browser.storage.local.get('notifications')
const ok = await browser.storage.local.get('notifications')
if (ok) {
let action = answer ? 'allowed' : 'denied'
const action = answer ? 'allowed' : 'denied'
browser.notifications.create(undefined, {
type: 'basic',
title: `${type} ${action} for ${host}`,