aboutsummaryrefslogtreecommitdiff
path: root/webext/chrome/popup.html
blob: b3482edaa680db2704242703f048625869ac64e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <title>Cerberus</title>
  <style>
    body { font-family: sans-serif; width: 280px; margin: 10px; }
    button { width: 100%; padding: 8px; margin: 6px 0; }
    input { width: 100%; padding: 6px; margin: 6px 0; }
  </style>
</head>
<body>
  <h3>Cerberus</h3>
  <input id="username" placeholder="Username" />
  <input id="password" placeholder="Password" type="password" />
  <button id="fetch">Fetch from Vault</button>
  <button id="fill">Fill on Page</button>
  <div id="status" style="font-size: 12px; color: #666; margin-top: 6px;"></div>
  <script>
    async function getActiveTab() {
      const tabs = await chrome.tabs.query({ active: true, currentWindow: true });
      return tabs[0];
    }
    function sendToBackground(msg) {
      return new Promise((resolve) => {
        chrome.runtime.sendMessage(msg, resolve);
      });
    }
    async function fill(username, password) {
      await sendToBackground({ type: 'FILL_CREDENTIALS', payload: { username, password } });
    }
    document.getElementById('fill').addEventListener('click', async () => {
      const username = document.getElementById('username').value;
      const password = document.getElementById('password').value;
      try {
        await fill(username, password);
        window.close();
      } catch (e) { console.error(e); }
    });
    document.getElementById('fetch').addEventListener('click', async () => {
      const status = document.getElementById('status');
      status.textContent = 'Fetching credentials from vault...';
      try {
        const resp = await sendToBackground({ type: 'GET_CREDENTIALS_FOR_TAB' });
        if (!resp || !resp.ok) { status.textContent = 'Failed to fetch (native host?)'; return; }
        const results = resp.result || [];
        if (results.length === 0) { status.textContent = 'No matching entries'; return; }
        const { username, password } = results[0];
        if (username) document.getElementById('username').value = username;
        if (password) document.getElementById('password').value = password;
        status.textContent = 'Fetched from vault';
      } catch (e) { console.error(e); status.textContent = 'Error'; }
    });
  </script>
</body>
</html>