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
File diff suppressed because it is too large Load Diff
+14 -17
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}`,
+11 -10
View File
@@ -3,12 +3,7 @@
"description": "Nostr Signer Extension",
"version": "0.1.2",
"homepage_url": "https://github.com/reyamir/nostr-connect",
"manifest_version": 2,
"browser_specific_settings": {
"gecko": {
"id": "{e665d138-0e5b-4b7a-ab91-7af834eda7a2}"
}
},
"manifest_version": 3,
"icons": {
"16": "icons/icon16.png",
"32": "icons/icon32.png",
@@ -17,19 +12,25 @@
},
"options_page": "options.html",
"background": {
"scripts": ["background.build.js"]
"service_worker": "background.build.js"
},
"browser_action": {
"action": {
"default_title": "Nostr Connect",
"default_popup": "popup.html"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content-script.build.js"]
"js": ["content-script.build.js"],
"all_frames": true
}
],
"permissions": ["storage"],
"optional_permissions": ["notifications"],
"web_accessible_resources": ["nostr-provider.js"]
"web_accessible_resources": [
{
"resources": ["nostr-provider.js"],
"matches": ["https://*/*", "http://localhost:*/*"]
}
]
}
+11 -9
View File
@@ -11,7 +11,7 @@ window.nostr = {
},
async signEvent(event) {
return this._call('signEvent', {event})
return this._call('signEvent', { event })
},
async getRelays() {
@@ -20,16 +20,16 @@ window.nostr = {
nip04: {
async encrypt(peer, plaintext) {
return window.nostr._call('nip04.encrypt', {peer, plaintext})
return window.nostr._call('nip04.encrypt', { peer, plaintext })
},
async decrypt(peer, ciphertext) {
return window.nostr._call('nip04.decrypt', {peer, ciphertext})
return window.nostr._call('nip04.decrypt', { peer, ciphertext })
}
},
_call(type, params) {
let id = Math.random().toString().slice(-4)
const id = Math.random().toString().slice(-4)
console.log(
'%c[nostrconnect:%c' +
id +
@@ -46,7 +46,7 @@ window.nostr = {
'font-weight:bold;color:#90b12d;font-family:monospace'
)
return new Promise((resolve, reject) => {
this._requests[id] = {resolve, reject}
this._requests[id] = { resolve, reject }
window.postMessage(
{
id,
@@ -60,7 +60,7 @@ window.nostr = {
}
}
window.addEventListener('message', message => {
window.addEventListener('message', (message) => {
if (
!message.data ||
message.data.response === null ||
@@ -71,8 +71,8 @@ window.addEventListener('message', message => {
return
if (message.data.response.error) {
let error = new Error(
`${EXTENSION}: ` + message.data.response.error.message
const error = new Error(
`${EXTENSION}: ${message.data.response.error.message}`
)
error.stack = message.data.response.error.stack
window.nostr._requests[message.data.id].reject(error)
@@ -104,7 +104,9 @@ async function replaceNostrSchemeLink(e) {
if (e.target.tagName !== 'A' || !e.target.href.startsWith('nostr:')) return
if (replacing === false) return
let response = await window.nostr._call('replaceURL', {url: e.target.href})
const response = await window.nostr._call('replaceURL', {
url: e.target.href
})
if (response === false) {
replacing = false
return
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long