browser-assistant 2.9.1 → 2.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -5
- package/extension/automation-policy.js +8 -4
- package/extension/background.js +1 -1
- package/extension/content.js +36 -23
- package/extension/journal-automation.js +2 -8
- package/extension/manifest.json +1 -1
- package/extension/popup.html +21 -52
- package/extension/question-visuals.js +6 -2
- package/extension/styles.css +473 -554
- package/package.json +1 -1
- package/server/journal.py +6 -3
- package/server/main.py +22 -22
- package/server/practice_quiz.html +79 -6
package/README.md
CHANGED
|
@@ -51,12 +51,15 @@ Download the backend ZIP or clone this repository, then open a terminal in the e
|
|
|
51
51
|
### Windows PowerShell
|
|
52
52
|
|
|
53
53
|
```powershell
|
|
54
|
-
|
|
54
|
+
if (-not (Test-Path '.\.venv\Scripts\python.exe')) {
|
|
55
|
+
py -3 -m venv .venv
|
|
56
|
+
}
|
|
55
57
|
.\.venv\Scripts\python.exe -m pip install --require-hashes -r server\requirements.lock.txt
|
|
56
|
-
|
|
58
|
+
if (-not (Test-Path 'server\.env')) {
|
|
59
|
+
Copy-Item server\.env.example server\.env
|
|
60
|
+
}
|
|
57
61
|
# Edit server\.env as described below, then:
|
|
58
|
-
|
|
59
|
-
..\.venv\Scripts\python.exe main.py
|
|
62
|
+
.\.venv\Scripts\python.exe server\main.py
|
|
60
63
|
```
|
|
61
64
|
|
|
62
65
|
### macOS / Linux
|
|
@@ -70,7 +73,7 @@ cd server
|
|
|
70
73
|
../.venv/bin/python main.py
|
|
71
74
|
```
|
|
72
75
|
|
|
73
|
-
Python 3.
|
|
76
|
+
Use Python 3.11 or later. If the Windows launcher cannot find your installed Python, use its full executable path in the environment creation command. For example, in PowerShell run `& 'C:\path\to\python.exe' -m venv .venv`. Install and run the backend through the same virtual environment.
|
|
74
77
|
|
|
75
78
|
### Configure a provider
|
|
76
79
|
|
|
@@ -78,10 +78,14 @@
|
|
|
78
78
|
const optionNodes = [...doc.querySelectorAll('[data-practice-option]')];
|
|
79
79
|
if (!question || optionNodes.length < 2)
|
|
80
80
|
return null;
|
|
81
|
-
const options = optionNodes.map((node, index) =>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
const options = optionNodes.map((node, index) => {
|
|
82
|
+
const text = (node.textContent || '').replace(/\s+/g, ' ').trim();
|
|
83
|
+
const label = String.fromCharCode(65 + index) + '. ';
|
|
84
|
+
return {
|
|
85
|
+
index, text: text.startsWith(label) ? text.slice(label.length) : text, node,
|
|
86
|
+
input: node.querySelector('input:not(:disabled)'),
|
|
87
|
+
};
|
|
88
|
+
});
|
|
85
89
|
if (options.some((option) => !option.input) || !question.textContent.trim())
|
|
86
90
|
return null;
|
|
87
91
|
return { text: question.textContent.replace(/\s+/g, ' ').trim(), options, form: question.closest('form') || doc.querySelector('form') };
|
package/extension/background.js
CHANGED
|
@@ -339,7 +339,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|
|
339
339
|
}
|
|
340
340
|
sendResponse({ ok: response.ok, status: response.status, data });
|
|
341
341
|
})
|
|
342
|
-
.catch(error => sendResponse({ error: error.name === 'TimeoutError' ? 'Local server request timed out.' : 'Local server is offline. Start it with
|
|
342
|
+
.catch(error => sendResponse({ error: error.name === 'TimeoutError' ? 'Local server request timed out.' : 'Local server is offline. Start it with the project virtual environment.' }))
|
|
343
343
|
.finally(() => { if (keepAlive !== null)
|
|
344
344
|
clearInterval(keepAlive); });
|
|
345
345
|
return true;
|
package/extension/content.js
CHANGED
|
@@ -76,7 +76,7 @@ function mountJournalCountdown(signal) {
|
|
|
76
76
|
return id;
|
|
77
77
|
};
|
|
78
78
|
const navigationCleanup = [];
|
|
79
|
-
console.log("Browser Assistant
|
|
79
|
+
console.log("Browser Assistant v" + extensionVersion + " loaded.");
|
|
80
80
|
const SERVER = 'http://localhost:8000';
|
|
81
81
|
const root = document.createElement('div');
|
|
82
82
|
root.id = 'assistant-root';
|
|
@@ -181,6 +181,16 @@ function mountJournalCountdown(signal) {
|
|
|
181
181
|
}
|
|
182
182
|
initDrag();
|
|
183
183
|
restorePanelPosition();
|
|
184
|
+
const panelResizeObserver = new ResizeObserver(() => {
|
|
185
|
+
if (!root.style.left || !root.offsetWidth || dragState.dragging)
|
|
186
|
+
return;
|
|
187
|
+
const { left, top } = root.getBoundingClientRect();
|
|
188
|
+
const { x, y } = clampPanelPosition(left, top);
|
|
189
|
+
if (left !== x || top !== y)
|
|
190
|
+
setPanelPosition(left, top);
|
|
191
|
+
});
|
|
192
|
+
panelResizeObserver.observe(root);
|
|
193
|
+
lifecycle.signal.addEventListener('abort', () => panelResizeObserver.disconnect(), { once: true });
|
|
184
194
|
let isCollapsed = true;
|
|
185
195
|
// Scan type and visible tab are intentionally separate. Switching away
|
|
186
196
|
// from QA Control must never stop an authorized automation run.
|
|
@@ -1861,8 +1871,13 @@ function mountJournalCountdown(signal) {
|
|
|
1861
1871
|
const response = await safeSendMessage({ action: 'apiRequest', path, method, body }, 370000);
|
|
1862
1872
|
if (!response)
|
|
1863
1873
|
throw new Error('Local server did not respond');
|
|
1864
|
-
if (response.error)
|
|
1874
|
+
if (response.error) {
|
|
1875
|
+
if (response.error.startsWith('Local server is offline'))
|
|
1876
|
+
setServerStatus(false);
|
|
1865
1877
|
throw new Error(response.error);
|
|
1878
|
+
}
|
|
1879
|
+
if (path !== '/health' && response.status)
|
|
1880
|
+
setServerStatus(true);
|
|
1866
1881
|
return response;
|
|
1867
1882
|
}
|
|
1868
1883
|
async function saveScanHistory(results, provider, scanType, language = null) {
|
|
@@ -1915,17 +1930,24 @@ function mountJournalCountdown(signal) {
|
|
|
1915
1930
|
}
|
|
1916
1931
|
}
|
|
1917
1932
|
// ── Server health check ───────────────────────────────────────────────────
|
|
1933
|
+
function setServerStatus(online) {
|
|
1934
|
+
serverOnline = online;
|
|
1935
|
+
const dot = root.querySelector('.status-dot');
|
|
1936
|
+
if (!dot)
|
|
1937
|
+
return;
|
|
1938
|
+
dot.classList.remove('unknown', 'online', 'offline');
|
|
1939
|
+
dot.classList.add(online ? 'online' : 'offline');
|
|
1940
|
+
dot.setAttribute('title', online ? 'Server online' : 'Server offline');
|
|
1941
|
+
}
|
|
1918
1942
|
async function checkServer() {
|
|
1943
|
+
let online = false;
|
|
1919
1944
|
try {
|
|
1920
1945
|
const res = await apiRequest('/health', 'GET');
|
|
1921
|
-
|
|
1946
|
+
online = res.ok;
|
|
1922
1947
|
}
|
|
1923
|
-
catch {
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
// Re-render if panel is open to show status
|
|
1927
|
-
if (!isCollapsed)
|
|
1928
|
-
render();
|
|
1948
|
+
catch { /* The next request can reconnect when the backend starts. */ }
|
|
1949
|
+
if (serverOnline === null)
|
|
1950
|
+
setServerStatus(online);
|
|
1929
1951
|
}
|
|
1930
1952
|
// Check once on load
|
|
1931
1953
|
checkServer();
|
|
@@ -2285,12 +2307,6 @@ function mountJournalCountdown(signal) {
|
|
|
2285
2307
|
if (isScanning)
|
|
2286
2308
|
return;
|
|
2287
2309
|
isScanning = true;
|
|
2288
|
-
// Show server-offline warning early
|
|
2289
|
-
if (serverOnline === false) {
|
|
2290
|
-
showError("Server offline. Start the backend with: python main.py");
|
|
2291
|
-
isScanning = false;
|
|
2292
|
-
return;
|
|
2293
|
-
}
|
|
2294
2310
|
isCollapsed = false;
|
|
2295
2311
|
render();
|
|
2296
2312
|
setLoading("Solving…");
|
|
@@ -2333,7 +2349,6 @@ function mountJournalCountdown(signal) {
|
|
|
2333
2349
|
}
|
|
2334
2350
|
const data = res.data;
|
|
2335
2351
|
await assertVisionQuestionCurrent(context);
|
|
2336
|
-
serverOnline = true;
|
|
2337
2352
|
let parsed;
|
|
2338
2353
|
try {
|
|
2339
2354
|
parsed = JSON.parse(data.results);
|
|
@@ -2360,10 +2375,6 @@ function mountJournalCountdown(signal) {
|
|
|
2360
2375
|
if (error.name === 'AbortError') {
|
|
2361
2376
|
showError("Request timed out — server may be busy, please try again");
|
|
2362
2377
|
}
|
|
2363
|
-
else if (error instanceof TypeError && error.message.includes('fetch')) {
|
|
2364
|
-
serverOnline = false;
|
|
2365
|
-
showError(`Error: ${error.message}`);
|
|
2366
|
-
}
|
|
2367
2378
|
else {
|
|
2368
2379
|
showError(`Error: ${error.message}`);
|
|
2369
2380
|
}
|
|
@@ -2551,7 +2562,7 @@ function mountJournalCountdown(signal) {
|
|
|
2551
2562
|
}
|
|
2552
2563
|
function scanPanelMarkup() {
|
|
2553
2564
|
return `
|
|
2554
|
-
<section class="assistant-scan-panel" id="assistant-scan-panel" role="tabpanel" aria-labelledby="mode-${selectedTab}">
|
|
2565
|
+
<section class="assistant-scan-panel" id="assistant-scan-panel" role="tabpanel" aria-labelledby="mode-${selectedTab === 'aptitude' ? 'apt' : selectedTab}">
|
|
2555
2566
|
<div class="assistant-btn-row">
|
|
2556
2567
|
<button class="assistant-btn" id="assistant-scan-btn">⚡ Scan (Text)</button>
|
|
2557
2568
|
<button class="assistant-btn secondary" id="assistant-vision-btn">⌁ Scan (Vision)</button>
|
|
@@ -2642,6 +2653,7 @@ function mountJournalCountdown(signal) {
|
|
|
2642
2653
|
const safeContent = content.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<');
|
|
2643
2654
|
root.innerHTML = `
|
|
2644
2655
|
<button class="assistant-tab collapsed ${content ? 'has-answer' : ''}" id="assistant-trigger" type="button" aria-label="Open Browser Assistant" data-content="${safeContent}">
|
|
2656
|
+
<span class="assistant-mark" aria-hidden="true">BA</span>
|
|
2645
2657
|
${isMinimalMode ? '<div class="assistant-mode-indicator">MIN</div>' : ''}
|
|
2646
2658
|
</button>
|
|
2647
2659
|
`;
|
|
@@ -2660,8 +2672,9 @@ function mountJournalCountdown(signal) {
|
|
|
2660
2672
|
<div class="assistant-tab" id="assistant-panel">
|
|
2661
2673
|
<div class="assistant-header">
|
|
2662
2674
|
<div class="assistant-title-row">
|
|
2663
|
-
|
|
2675
|
+
<span class="assistant-mark" aria-hidden="true">BA</span>
|
|
2664
2676
|
<h3 class="assistant-title">Browser Assistant</h3>
|
|
2677
|
+
${statusDot}
|
|
2665
2678
|
</div>
|
|
2666
2679
|
<div class="assistant-header-actions">
|
|
2667
2680
|
<button class="assistant-icon-btn" id="assistant-history-btn" type="button" aria-label="Open Scan History" title="Scan History">
|
|
@@ -2693,7 +2706,7 @@ function mountJournalCountdown(signal) {
|
|
|
2693
2706
|
bindTabKeyboardNavigation();
|
|
2694
2707
|
document.getElementById('assistant-history-btn').onclick = openHistory;
|
|
2695
2708
|
document.getElementById('assistant-scan-btn')?.addEventListener('click', scanPage);
|
|
2696
|
-
document.getElementById('assistant-vision-btn')?.addEventListener('click', visionScan);
|
|
2709
|
+
document.getElementById('assistant-vision-btn')?.addEventListener('click', () => { void visionScan(); });
|
|
2697
2710
|
document.getElementById('assistant-auto-start-btn')?.addEventListener('click', startPracticeAutomation);
|
|
2698
2711
|
document.getElementById('assistant-export-question-btn')?.addEventListener('click', exportQuestionDiagnostic);
|
|
2699
2712
|
document.getElementById('assistant-auto-pause-btn')?.addEventListener('click', pauseOrResumeAutomation);
|
|
@@ -132,15 +132,10 @@ function browserAssistantJournal(global) {
|
|
|
132
132
|
const panel = document.createElement('section');
|
|
133
133
|
panel.id = 'assistant-journal';
|
|
134
134
|
panel.dataset.build = journalBuild;
|
|
135
|
-
panel.
|
|
136
|
-
panel.innerHTML = '<strong>Reflective Journal</strong><p data-info></p><p data-countdown style="font-weight:600;margin:8px 0"></p><textarea aria-label="Your class experience and feelings" placeholder="Your actual class experience / feelings (optional)" rows="3" style="width:100%;box-sizing:border-box"></textarea><button type="button" style="margin-top:8px;padding:10px">Fill & Submit Journal</button><p role="status" aria-live="polite"></p>';
|
|
135
|
+
panel.innerHTML = '<strong>Reflective Journal</strong><p data-info></p><p data-countdown></p><textarea aria-label="Your class experience and feelings" placeholder="Your actual class experience / feelings (optional)" rows="3"></textarea><button type="button">Fill & Submit Journal</button><p role="status" aria-live="polite"></p>';
|
|
137
136
|
document.body.appendChild(panel);
|
|
138
137
|
const controls = document.createElement('div');
|
|
139
138
|
controls.innerHTML = '<label>Subject <select data-subject aria-label="Journal subject"><option value="">Detect from page</option><option>Backend Development Fundamentals</option><option>Computer Organization and Architecture</option><option>Advanced Data Structures</option><option>Linear Algebra Essentials</option><option>Fundamentals of Artificial Intelligence</option></select></label><label>Module / Journal <select data-number aria-label="Journal number"><option value="">Detect from page</option>' + Array.from({ length: 10 }, (_, i) => `<option value="${i + 1}">${i + 1}</option>`).join('') + '</select></label>';
|
|
140
|
-
for (const label of controls.querySelectorAll('label'))
|
|
141
|
-
label.style.cssText = 'display:block;margin:8px 0';
|
|
142
|
-
for (const select of controls.querySelectorAll('select'))
|
|
143
|
-
select.style.cssText = 'display:block;width:100%;padding:5px;color:#17233d;background:white;border:1px solid #abb3c3';
|
|
144
139
|
panel.insertBefore(controls, panel.querySelector('textarea'));
|
|
145
140
|
const status = panel.querySelector('[role=status]'), button = panel.querySelector('button');
|
|
146
141
|
const countdown = panel.querySelector('[data-countdown]');
|
|
@@ -234,7 +229,6 @@ function browserAssistantJournal(global) {
|
|
|
234
229
|
button.setAttribute('aria-keyshortcuts', 'Alt+Shift+J');
|
|
235
230
|
const shortcutHint = document.createElement('p');
|
|
236
231
|
shortcutHint.textContent = 'Shortcut: Alt + Shift + J';
|
|
237
|
-
shortcutHint.style.cssText = 'font-size:12px;margin:6px 0;color:#516078';
|
|
238
232
|
panel.insertBefore(shortcutHint, status);
|
|
239
233
|
const shortcutListener = event => {
|
|
240
234
|
if (!event.altKey || !event.shiftKey || event.ctrlKey || event.metaKey || event.repeat || event.isComposing)
|
|
@@ -277,7 +271,7 @@ function browserAssistantJournal(global) {
|
|
|
277
271
|
if (slot) {
|
|
278
272
|
if (panel.parentElement !== slot)
|
|
279
273
|
slot.appendChild(panel);
|
|
280
|
-
panel.style.
|
|
274
|
+
panel.style.display = '';
|
|
281
275
|
button.hidden = true;
|
|
282
276
|
}
|
|
283
277
|
else
|
package/extension/manifest.json
CHANGED
package/extension/popup.html
CHANGED
|
@@ -4,59 +4,28 @@
|
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>Browser Assistant</title>
|
|
7
|
-
<
|
|
8
|
-
body {
|
|
9
|
-
width: 220px;
|
|
10
|
-
padding: 12px 14px;
|
|
11
|
-
font-family: 'Inter', system-ui, sans-serif;
|
|
12
|
-
background: #0f0f0f;
|
|
13
|
-
color: #eee;
|
|
14
|
-
margin: 0;
|
|
15
|
-
}
|
|
16
|
-
.logo {
|
|
17
|
-
display: flex;
|
|
18
|
-
align-items: center;
|
|
19
|
-
gap: 8px;
|
|
20
|
-
margin-bottom: 10px;
|
|
21
|
-
}
|
|
22
|
-
.logo-dot {
|
|
23
|
-
width: 10px;
|
|
24
|
-
height: 10px;
|
|
25
|
-
border-radius: 50%;
|
|
26
|
-
background: #6e8efb;
|
|
27
|
-
box-shadow: 0 0 6px #6e8efb;
|
|
28
|
-
}
|
|
29
|
-
h3 { margin: 0; font-size: 14px; color: #fff; }
|
|
30
|
-
p { font-size: 11px; color: #888; margin: 0 0 10px; line-height: 1.5; }
|
|
31
|
-
.status { font-size: 11px; color: #555; }
|
|
32
|
-
.status span { color: #10b981; font-weight: 600; }
|
|
33
|
-
.shortcuts { margin-top: 10px; border-top: 1px solid #222; padding-top: 8px; }
|
|
34
|
-
.shortcut-row { display: flex; justify-content: space-between; font-size: 10px; color: #666; margin-bottom: 4px; }
|
|
35
|
-
kbd {
|
|
36
|
-
background: #222; border: 1px solid #444; border-radius: 3px;
|
|
37
|
-
padding: 1px 5px; font-size: 10px; color: #bbb;
|
|
38
|
-
}
|
|
39
|
-
#server-status { color: #f59e0b; }
|
|
40
|
-
#server-status.online { color: #10b981; }
|
|
41
|
-
#server-status.offline { color: #ef4444; }
|
|
42
|
-
</style>
|
|
7
|
+
<link rel="stylesheet" href="styles.css">
|
|
43
8
|
</head>
|
|
44
|
-
<body>
|
|
45
|
-
<
|
|
46
|
-
<
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
<
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
9
|
+
<body class="assistant-popup">
|
|
10
|
+
<main class="popup-shell">
|
|
11
|
+
<header class="popup-title">
|
|
12
|
+
<span class="popup-mark" aria-hidden="true">BA</span>
|
|
13
|
+
<h1>Browser Assistant</h1>
|
|
14
|
+
</header>
|
|
15
|
+
<section class="popup-card" aria-label="Server status">
|
|
16
|
+
<div>Server <span id="server-status" role="status">Checking…</span></div>
|
|
17
|
+
<p id="journal-countdown" hidden></p>
|
|
18
|
+
</section>
|
|
19
|
+
<section class="popup-card" aria-labelledby="popup-shortcuts">
|
|
20
|
+
<h2 id="popup-shortcuts">Keyboard shortcuts</h2>
|
|
21
|
+
<div class="shortcut-row"><span>Open panel</span> <kbd>`</kbd></div>
|
|
22
|
+
<div class="shortcut-row"><span>Close panel</span> <kbd>]</kbd></div>
|
|
23
|
+
<div class="shortcut-row"><span>Vision scan</span> <kbd>\</kbd></div>
|
|
24
|
+
<div class="shortcut-row"><span>Minimal mode</span> <kbd>[</kbd></div>
|
|
25
|
+
<div class="shortcut-row"><span>Fill and submit journal</span> <kbd>Alt+Shift+J</kbd></div>
|
|
26
|
+
<div class="shortcut-row"><span>Start, pause or resume</span> <kbd>Alt+A</kbd></div>
|
|
27
|
+
</section>
|
|
28
|
+
</main>
|
|
60
29
|
<script src="popup.js"></script>
|
|
61
30
|
</body>
|
|
62
31
|
</html>
|
|
@@ -3,12 +3,16 @@
|
|
|
3
3
|
(function () {
|
|
4
4
|
function nodes(question) {
|
|
5
5
|
const found = new Set();
|
|
6
|
-
|
|
6
|
+
const optionRegions = question.options.map(option => option.node).filter(Boolean);
|
|
7
|
+
for (const region of [question.visualRegion, ...optionRegions]) {
|
|
7
8
|
if (!region)
|
|
8
9
|
continue;
|
|
9
10
|
const candidates = region.matches('img,svg,canvas') ? [region] : region.querySelectorAll('img,svg,canvas');
|
|
10
11
|
for (const node of candidates) {
|
|
11
|
-
if (node.closest('#assistant-root,nav,aside
|
|
12
|
+
if (node.closest('#assistant-root,nav,aside') || !node.getClientRects().length)
|
|
13
|
+
continue;
|
|
14
|
+
const button = node.closest('button');
|
|
15
|
+
if (button && !optionRegions.some(option => button.contains(option) && option.contains(node)))
|
|
12
16
|
continue;
|
|
13
17
|
if (node.parentElement?.closest('svg'))
|
|
14
18
|
continue;
|