+
+
+ {privKey === '' && }
+ {privKey && hidingPrivateKey && }
+ {privKey && !hidingPrivateKey && }
+
+ {privKey && !isKeyValid() &&
private key is invalid!
}
+ {!hidingPrivateKey && isKeyValid() && (
)}
-
-
- hidePrivateKey(false)}
- onBlur={() => hidePrivateKey(true)}
- />
- {privKey === '' && }
-
-
-
+
preferred relays:
+
+ {relays.map(({url, policy}, i) => (
+
+ ))}
+
+ setNewRelayURL(e.target.value)}
+ onKeyDown={e => { if (e.key === 'Enter') addNewRelay()}}
+ />
+
-
-
-
- | domain |
- permission |
- answer |
- conditions |
- since |
- |
-
-
-
- {policies.map(
- ({host, type, accept, conditions, created_at}) => (
-
- | {host} |
- {type} |
- {accept} |
-
- {conditions.kinds
- ? `kinds: ${Object.keys(conditions.kinds).join(', ')}`
- : 'always'}
- |
-
- {new Date(created_at * 1000)
- .toISOString()
- .split('.')[0]
- .split('T')
- .join(' ')}
- |
-
-
- |
-
- )
- )}
-
-
- >
- )}
-
-
-
- handle{' '}
- nostr:{' '}
- links:
-
-
+
+
+
+
+ {messages.map((message, i) => (
+
{message}
+ ))}
-
{message}
+
+
permissions
+
+
+
+ | domain |
+ permission |
+ answer |
+ conditions |
+ since |
+ |
+
+
+
+ {policies.map(
+ ({host, type, accept, conditions, created_at}) => (
+
+ | {host} |
+ {type} |
+ {accept} |
+
+ {conditions.kinds
+ ? `kinds: ${Object.keys(conditions.kinds).join(', ')}`
+ : 'always'}
+ |
+
+ {new Date(created_at * 1000)
+ .toISOString()
+ .split('.')[0]
+ .split('T')
+ .join(' ')}
+ |
+
+
+ |
+
+ )
+ )}
+ {!policies.length && {Array(5).fill('N/A').map((v, i) => (| {v} | ))}
}
+
+
+ {!policies.length &&
no permissions have been granted yet
}
+
>
)
async function handleKeyChange(e) {
let key = e.target.value.toLowerCase().trim()
setPrivKey(key)
+ addUnsavedChanges('private_key')
}
async function generate() {
setPrivKey(nip19.nsecEncode(generatePrivateKey()))
+ addUnsavedChanges('private_key')
}
async function saveKey() {
- if (!isKeyValid()) return
+ if (!isKeyValid()) {
+ showMessage('PRIVATE KEY IS INVALID! did not save private key.')
+ return
+ }
let hexOrEmptyKey = privKey
@@ -341,6 +326,7 @@ function Options() {
{url: ev.target.value, policy: relays[i].policy},
...relays.slice(i + 1)
])
+ addUnsavedChanges('relays')
}
function toggleRelayPolicy(i, cat) {
@@ -352,6 +338,7 @@ function Options() {
},
...relays.slice(i + 1)
])
+ addUnsavedChanges('relays')
}
function removeRelay(i) {
@@ -359,6 +346,7 @@ function Options() {
...relays.slice(0, i),
...relays.slice(i + 1)
])
+ addUnsavedChanges('relays')
}
function addNewRelay() {
@@ -368,6 +356,7 @@ function Options() {
policy: {read: true, write: true}
})
setRelays(relays)
+ addUnsavedChanges('relays')
setNewRelayURL('')
}
@@ -386,19 +375,22 @@ function Options() {
}
}
- async function handleNotifications() {
- if (showNotifications) {
- await browser.storage.local.set({notifications: false})
- setNotifications(false)
- } else {
- let granted = await browser.permissions.request({
- permissions: ['notifications']
- })
- if (granted) {
- await browser.storage.local.set({notifications: true})
- setNotifications(true)
- }
- }
+ function handleNotifications() {
+ setNotifications(!showNotifications)
+ addUnsavedChanges('notifications')
+ if (!showNotifications) requestBrowserNotificationPermissions()
+ }
+
+ async function requestBrowserNotificationPermissions() {
+ let granted = await browser.permissions.request({
+ permissions: ['notifications']
+ })
+ if (!granted) setNotifications(false)
+ }
+
+ async function saveNotifications() {
+ await browser.storage.local.set({notifications: showNotifications})
+ showMessage('saved notifications!')
}
async function saveRelays() {
@@ -412,23 +404,54 @@ function Options() {
showMessage('saved relays!')
}
+ function changeShowProtocolHandlerHelp() {
+ setShowProtocolHandlerHelp(true)
+ }
+
+ function changeHandleNostrLinks() {
+ if (handleNostrLinks) {
+ setProtocolHandler('')
+ addUnsavedChanges('protocol_handler')
+ } else setShowProtocolHandlerHelp(true)
+ setHandleNostrLinks(!handleNostrLinks)
+ }
+
function handleChangeProtocolHandler(e) {
- if (e.target.type === 'text') setProtocolHandler(e.target.value)
- else
- switch (e.target.value) {
- case 'no':
- setProtocolHandler(null)
- break
- case 'yes':
- setProtocolHandler('')
- break
- }
+ setProtocolHandler(e.target.value)
+ addUnsavedChanges('protocol_handler')
}
async function saveNostrProtocolHandlerSettings() {
await browser.storage.local.set({protocol_handler: protocolHandler})
showMessage('saved protocol handler!')
}
+
+ function addUnsavedChanges(section) {
+ if (!unsavedChanges.find(s => s === section)) {
+ unsavedChanges.push(section)
+ setUnsavedChanges(unsavedChanges)
+ }
+ }
+
+ async function saveChanges() {
+ for (let section of unsavedChanges) {
+ switch (section) {
+ case 'private_key':
+ await saveKey()
+ break
+ case 'relays':
+ await saveRelays()
+ break
+ case 'protocol_handler':
+ await saveNostrProtocolHandlerSettings()
+ break
+ case 'notifications':
+ await saveNotifications()
+ break
+ }
+ }
+ setUnsavedChanges([])
+ }
}
render(
, document.getElementById('main'))