Oregami
Repositories/oxedyne/daimond

oxedyne/daimond/verify/ext/popup.js

1.7 KiB, 1 run

created by r2519314175:1019, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1// verify/ext/popup.js — show the active tab's verdict, and let the user re-run.
2
3const dot = document.getElementById('dot');
4const headline = document.getElementById('headline');
5const checksEl = document.getElementById('checks');
6const idsEl = document.getElementById('ids');
7const btn = document.getElementById('recheck');
8
9function mark(c) { return c.ok === true ? ['ok', '✓'] : c.ok === false ? ['no', '✗'] : ['warn', '?']; }
10
11function render(v) {
12 if (!v) {
13 dot.className = 'dot';
14 headline.textContent = 'Not a Daimond page, or not checked yet.';
15 checksEl.innerHTML = ''; idsEl.textContent = '';
16 return;
17 }
18 dot.className = 'dot ' + (v.ok ? 'ok' : v.failed ? 'no' : 'warn');
19 headline.textContent = v.ok ? 'Published source, sealed.'
20 : v.failed ? 'Does NOT match the published source.'
21 : 'Could not fully verify.';
22 checksEl.innerHTML = '';
23 (v.checks || []).forEach(c => {
24 const m = mark(c);
25 const li = document.createElement('li');
26 li.innerHTML = '<span class="mk ' + m[0] + '">' + m[1] + '</span>'
27 + '<span>' + c.name + (c.detail ? ' <span class="dt">— ' + c.detail + '</span>' : '') + '</span>';
28 checksEl.appendChild(li);
29 });
30 idsEl.textContent = v.build ? 'build ' + v.build + '\nbundle ' + v.bundle : '';
31}
32
33async function activeTab() {
34 const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
35 return tab;
36}
37
38async function load() {
39 const tab = await activeTab();
40 const v = await chrome.runtime.sendMessage({ type: 'verdict', tabId: tab.id });
41 render(v);
42}
43
44btn.addEventListener('click', async () => {
45 const tab = await activeTab();
46 headline.textContent = 'Checking…'; dot.className = 'dot';
47 const v = await chrome.runtime.sendMessage({ type: 'recheck', tabId: tab.id, url: tab.url });
48 render(v);
49});
50
51load();