aboutsummaryrefslogtreecommitdiffstats
path: root/extension/src/prompt.js
blob: 6637f70729fa7361444e784240c4dcbe9835312e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// The one question a site ever gets asked: may it use the key (or the
// wallet)? "Always allow" is remembered; the site is not asked again.
const q = new URLSearchParams(location.search);
const origin = q.get('origin') || '';
const kind = q.get('kind') === 'pay' ? 'pay' : 'sign';
const $ = (id) => document.getElementById(id);
$('origin').textContent = origin.replace(/^https:\/\//, '');
$('what').textContent = kind === 'pay' ? 'Let this site use your wallet?' : 'Let this site use your nostr key?';
$('detail').textContent = kind === 'pay'
  ? 'It will be able to see your balance, create invoices and send payments without asking, within the limit you set on the wallet connection.'
  : 'It will be able to see your public key, sign as you and read your private messages, without asking again.';
const answer = async (choice) => {
  for (const b of document.querySelectorAll('button')) b.disabled = true;
  await chrome.runtime.sendMessage({ type: 'answer', id: q.get('id'), origin, kind, choice });
  window.close();
};
$('allow').onclick = () => answer('always');
$('deny').onclick = () => answer('deny');
$('never').onclick = () => answer('never');
$('allow').focus();