browser-assistant 2.8.25 → 2.9.0
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 +14 -11
- package/extension/answer-requests.js +33 -0
- package/extension/automation-policy.js +2 -1
- package/extension/background.js +199 -86
- package/extension/content.js +239 -101
- package/extension/editor-bridge.js +7 -11
- package/extension/journal-automation.js +102 -254
- package/extension/manifest.json +13 -4
- package/extension/popup.html +13 -17
- package/extension/popup.js +40 -43
- package/extension/question-visuals.js +80 -1
- package/extension/styles.css +7 -0
- package/package.json +5 -2
- package/server/.env.example +2 -0
- package/server/inference_jobs.py +90 -0
- package/server/journal.py +2 -1
- package/server/local_security.py +74 -1
- package/server/main.py +62 -7
|
@@ -88,8 +88,8 @@ function browserAssistantEditor(operation, selector, expected, value) {
|
|
|
88
88
|
return { ok: false, error: error.message };
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
-
// Run the IDE's normal paste and autosave flow. The terminal
|
|
92
|
-
//
|
|
91
|
+
// Run the IDE's normal paste and autosave flow. The terminal verifies the saved
|
|
92
|
+
// file and checks syntax. The portal's grading command is a separate user action.
|
|
93
93
|
async function browserAssistantOnlineIde(action, workspace, questionId, token, source) {
|
|
94
94
|
if (location.origin !== 'https://ide.ccbp.in' || location.pathname.replace(/\/$/, '') !== `/playground/${workspace}`)
|
|
95
95
|
return null;
|
|
@@ -116,16 +116,12 @@ async function browserAssistantOnlineIde(action, workspace, questionId, token, s
|
|
|
116
116
|
const result = lines.find(line => line.startsWith(`${finishMarker}:`));
|
|
117
117
|
if (!result)
|
|
118
118
|
return { ok: true, done: false };
|
|
119
|
-
|
|
120
|
-
const report = index >= 0 && reports(lines.slice(index)).find(id => !previous.reports.includes(id));
|
|
121
|
-
const passed = result === `${finishMarker}:0` && Boolean(report) && index > 0
|
|
122
|
-
&& lines.slice(Math.max(0, index - 3), index).includes('All test cases passed');
|
|
123
|
-
return { ok: true, done: true, passed, submitted: Boolean(report), saveUnconfirmed: lines.includes(saveMarker), url: report ? reportPrefix + report : null };
|
|
119
|
+
return { ok: true, done: true, saved: result === `${finishMarker}:0`, saveUnconfirmed: lines.includes(saveMarker) };
|
|
124
120
|
}
|
|
125
121
|
if (previous?.token === token)
|
|
126
122
|
return { ok: false, error: 'This IDE run was already started. Check the terminal.' };
|
|
127
123
|
if (document.visibilityState !== 'visible')
|
|
128
|
-
return { ok: false, error: 'Keep the matching IDE tab active to
|
|
124
|
+
return { ok: false, error: 'Keep the matching IDE tab active to apply code.' };
|
|
129
125
|
const before = rows();
|
|
130
126
|
const prompt = before.at(-1)?.match(/^nxtwave@([a-z0-9]+):~\/nodejs\/coding-practices\/([a-z0-9_-]+)\$$/i);
|
|
131
127
|
if (!prompt || prompt[1] !== workspace)
|
|
@@ -198,15 +194,15 @@ async function browserAssistantOnlineIde(action, workspace, questionId, token, s
|
|
|
198
194
|
// All interpolated values have restricted alphabets.
|
|
199
195
|
const saved = `printf '%s app.js\\n' '${digest}' | sha256sum --check --status`;
|
|
200
196
|
const echoMarker = `BA_COMMAND_${token}`;
|
|
201
|
-
const command = `( for ba_try in 1 2 3 4 5 6 7 8 9 10; do ${saved} && break; sleep 0.5; done; if ${saved}; then node --check app.js
|
|
197
|
+
const command = `( for ba_try in 1 2 3 4 5 6 7 8 9 10; do ${saved} && break; sleep 0.5; done; if ${saved}; then node --check app.js; else printf '%s\\n' ${saveMarker}; false; fi ); printf '\\n${finishMarker}:%s\\n' "$?" #${echoMarker}`;
|
|
202
198
|
if (rows().at(-1) !== before.at(-1))
|
|
203
|
-
return { ok: false, error: 'Code is in app.js, but the IDE terminal changed before
|
|
199
|
+
return { ok: false, error: 'Code is in app.js, but the IDE terminal changed before the syntax check.' };
|
|
204
200
|
input.focus();
|
|
205
201
|
if (document.activeElement !== input)
|
|
206
202
|
return { ok: false, error: 'The IDE terminal could not be focused.' };
|
|
207
203
|
const data = new DataTransfer();
|
|
208
204
|
data.setData('text/plain', command);
|
|
209
|
-
window[key] = { token
|
|
205
|
+
window[key] = { token };
|
|
210
206
|
input.dispatchEvent(new ClipboardEvent('paste', { clipboardData: data, bubbles: true, cancelable: true }));
|
|
211
207
|
const deadline = Date.now() + 2500;
|
|
212
208
|
while (Date.now() < deadline && document.activeElement === input && document.visibilityState === 'visible') {
|
|
@@ -96,19 +96,7 @@ function browserAssistantJournal(global) {
|
|
|
96
96
|
}
|
|
97
97
|
return values.size === 1 ? [...values][0] : null;
|
|
98
98
|
}
|
|
99
|
-
|
|
100
|
-
const win = field.ownerDocument.defaultView;
|
|
101
|
-
if (field.tagName === 'TEXTAREA') {
|
|
102
|
-
Object.getOwnPropertyDescriptor(win.HTMLTextAreaElement.prototype, 'value').set.call(field, value);
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
field.textContent = value;
|
|
106
|
-
}
|
|
107
|
-
const event = win.InputEvent ? new win.InputEvent('input', { bubbles: true, inputType: 'insertText', data: value }) : new win.Event('input', { bubbles: true });
|
|
108
|
-
field.dispatchEvent(event);
|
|
109
|
-
field.dispatchEvent(new win.Event('change', { bubbles: true }));
|
|
110
|
-
}
|
|
111
|
-
const api = { validate, metadata, fields, pageText, readField, writeField, remainingSeconds };
|
|
99
|
+
const api = { validate, metadata, fields, pageText, readField, remainingSeconds };
|
|
112
100
|
if (typeof module !== 'undefined')
|
|
113
101
|
module.exports = api;
|
|
114
102
|
if (!global.document || global.location?.origin !== 'https://admissions.aurora.edu.in')
|
|
@@ -123,8 +111,8 @@ function browserAssistantJournal(global) {
|
|
|
123
111
|
return;
|
|
124
112
|
existing?.remove();
|
|
125
113
|
const storageKey = `assistantJournal:${location.pathname}`;
|
|
126
|
-
let info = null,
|
|
127
|
-
let
|
|
114
|
+
let info = null, running = false, paused = false, generation = 0, idleState = 'READY';
|
|
115
|
+
let activeRequest;
|
|
128
116
|
try {
|
|
129
117
|
info = JSON.parse(sessionStorage.getItem(storageKey));
|
|
130
118
|
}
|
|
@@ -133,7 +121,7 @@ function browserAssistantJournal(global) {
|
|
|
133
121
|
panel.id = 'assistant-journal';
|
|
134
122
|
panel.dataset.build = journalBuild;
|
|
135
123
|
panel.style.cssText = 'position:fixed;right:16px;top:160px;width:290px;z-index:2147483646;background:white;color:#17233d;padding:16px;border:2px solid #7638ff;border-radius:12px;box-shadow:0 4px 20px #0003;font:14px Arial';
|
|
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="
|
|
124
|
+
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="Describe your actual class experience and how you felt" rows="3" style="width:100%;box-sizing:border-box"></textarea><button type="button" style="margin-top:8px;padding:10px">Prepare Journal Draft</button><p role="status" aria-live="polite"></p>';
|
|
137
125
|
document.body.appendChild(panel);
|
|
138
126
|
const controls = document.createElement('div');
|
|
139
127
|
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>';
|
|
@@ -185,8 +173,8 @@ function browserAssistantJournal(global) {
|
|
|
185
173
|
countdown.textContent = text;
|
|
186
174
|
}
|
|
187
175
|
async function recordJournalConfirmation() {
|
|
188
|
-
if (!journalConfirmed &&
|
|
189
|
-
/^(?:journal (?:has been )?submitted successfully|journal submission successful)[.!]?$/i.test(node.textContent.trim())))
|
|
176
|
+
if (!journalConfirmed && [...document.querySelectorAll('p,h1,h2,h3,[role=status],[role=alert]')].some(node => !node.closest('#assistant-root,#assistant-journal,[contenteditable]') && node.getClientRects().length &&
|
|
177
|
+
/^(?:journal (?:has been )?submitted successfully|journal submission successful)[.!]?$/i.test(node.textContent.trim()))) {
|
|
190
178
|
try {
|
|
191
179
|
await global.chrome?.storage?.local.set({ [`assistantJournalConfirmed:${journalPath}`]: true });
|
|
192
180
|
journalConfirmed = true;
|
|
@@ -230,14 +218,14 @@ function browserAssistantJournal(global) {
|
|
|
230
218
|
publishedDeadline = undefined;
|
|
231
219
|
}
|
|
232
220
|
}
|
|
233
|
-
button.title = '
|
|
221
|
+
button.title = 'Prepare Journal Draft (Alt + Shift + J)';
|
|
234
222
|
button.setAttribute('aria-keyshortcuts', 'Alt+Shift+J');
|
|
235
223
|
const shortcutHint = document.createElement('p');
|
|
236
224
|
shortcutHint.textContent = 'Shortcut: Alt + Shift + J';
|
|
237
225
|
shortcutHint.style.cssText = 'font-size:12px;margin:6px 0;color:#516078';
|
|
238
226
|
panel.insertBefore(shortcutHint, status);
|
|
239
227
|
const shortcutListener = event => {
|
|
240
|
-
if (!event.altKey || !event.shiftKey || event.ctrlKey || event.metaKey || event.repeat || event.isComposing)
|
|
228
|
+
if (!event.isTrusted || !event.altKey || !event.shiftKey || event.ctrlKey || event.metaKey || event.repeat || event.isComposing)
|
|
241
229
|
return;
|
|
242
230
|
if (event.code !== 'KeyJ' && String(event.key).toLowerCase() !== 'j')
|
|
243
231
|
return;
|
|
@@ -245,7 +233,7 @@ function browserAssistantJournal(global) {
|
|
|
245
233
|
return;
|
|
246
234
|
event.preventDefault();
|
|
247
235
|
if (!running && !button.disabled)
|
|
248
|
-
|
|
236
|
+
void prepareDraft();
|
|
249
237
|
};
|
|
250
238
|
document.addEventListener('keydown', shortcutListener, true);
|
|
251
239
|
function notify() {
|
|
@@ -253,23 +241,19 @@ function browserAssistantJournal(global) {
|
|
|
253
241
|
}
|
|
254
242
|
const controller = {
|
|
255
243
|
path: location.pathname,
|
|
256
|
-
start() {
|
|
244
|
+
start() { return prepareDraft(); },
|
|
257
245
|
stop() {
|
|
246
|
+
activeRequest?.abort();
|
|
258
247
|
generation++;
|
|
259
|
-
draft = null;
|
|
260
248
|
running = false;
|
|
261
249
|
paused = false;
|
|
262
|
-
submitting = false;
|
|
263
|
-
starting = false;
|
|
264
|
-
filled = false;
|
|
265
|
-
waitingForTimer = false;
|
|
266
250
|
idleState = 'STOPPED';
|
|
267
251
|
global.BrowserAssistantJournalBusy = false;
|
|
268
252
|
button.disabled = false;
|
|
269
|
-
status.textContent = '
|
|
253
|
+
status.textContent = 'Draft preparation stopped.';
|
|
270
254
|
notify();
|
|
271
255
|
},
|
|
272
|
-
pause() { if (!running
|
|
256
|
+
pause() { if (!running)
|
|
273
257
|
return; paused = !paused; notify(); },
|
|
274
258
|
mount(slot) {
|
|
275
259
|
if (!document.getElementById('assistant-root'))
|
|
@@ -291,11 +275,13 @@ function browserAssistantJournal(global) {
|
|
|
291
275
|
}
|
|
292
276
|
},
|
|
293
277
|
getState() {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
278
|
+
const completed = journalConfirmed ? 1 : 0;
|
|
279
|
+
return { running, paused,
|
|
280
|
+
state: completed ? 'COMPLETED' : paused ? 'PAUSED' : running ? 'PREPARING' : idleState,
|
|
281
|
+
message: completed ? 'Submission confirmed by the portal.' : paused ? 'Paused. Resume to review the draft.'
|
|
282
|
+
: status.textContent || 'Prepare an editable draft before starting the portal assessment.',
|
|
283
|
+
title: info ? info.subject + ' · Module ' + info.number : 'Select subject and module',
|
|
284
|
+
completed };
|
|
299
285
|
},
|
|
300
286
|
};
|
|
301
287
|
if (global.BrowserAssistantJournal) {
|
|
@@ -304,7 +290,7 @@ function browserAssistantJournal(global) {
|
|
|
304
290
|
}
|
|
305
291
|
function assertCurrentPage() {
|
|
306
292
|
if (!document.contains(panel) || storageKey !== `assistantJournal:${location.pathname}`)
|
|
307
|
-
throw Error('Journal page changed.
|
|
293
|
+
throw Error('Journal page changed. Draft preparation stopped.');
|
|
308
294
|
if (/assessment not found/i.test(document.querySelector('main')?.textContent || ''))
|
|
309
295
|
throw Error('Assessment is unavailable. Return to Assessments and check its status.');
|
|
310
296
|
}
|
|
@@ -329,213 +315,105 @@ function browserAssistantJournal(global) {
|
|
|
329
315
|
controls.hidden = Boolean(info);
|
|
330
316
|
panel.querySelector('[data-info]').textContent = info ? `${info.subject} · Module ${info.number} · 400 words (80 per section)` : 'Subject not detected yet. Select the subject and journal number below, or open Module Information.';
|
|
331
317
|
}
|
|
332
|
-
|
|
333
|
-
|
|
318
|
+
const preview = document.createElement('section');
|
|
319
|
+
preview.hidden = true;
|
|
320
|
+
preview.setAttribute('aria-label', 'Editable journal draft');
|
|
321
|
+
panel.insertBefore(preview, status);
|
|
322
|
+
const editors = Object.fromEntries(keys.map((key, index) => {
|
|
323
|
+
const group = document.createElement('label');
|
|
324
|
+
group.style.display = 'block';
|
|
325
|
+
const count = document.createElement('span');
|
|
326
|
+
const editor = document.createElement('textarea');
|
|
327
|
+
editor.rows = 4;
|
|
328
|
+
editor.style.width = '100%';
|
|
329
|
+
const updateCount = () => {
|
|
330
|
+
const words = editor.value.trim() ? editor.value.trim().split(/\\s+/u).length : 0;
|
|
331
|
+
count.textContent = labels[index] + ' (' + words + '/80 words)';
|
|
332
|
+
};
|
|
333
|
+
editor.addEventListener('input', updateCount);
|
|
334
|
+
group.append(count, editor);
|
|
335
|
+
preview.appendChild(group);
|
|
336
|
+
return [key, { editor, updateCount }];
|
|
337
|
+
}));
|
|
338
|
+
const copy = document.createElement('button');
|
|
339
|
+
copy.type = 'button';
|
|
340
|
+
copy.textContent = 'Copy reviewed draft';
|
|
341
|
+
copy.addEventListener('click', async (event) => {
|
|
342
|
+
if (!event.isTrusted)
|
|
334
343
|
return;
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
try {
|
|
341
|
-
// The user explicitly requested automatic declaration/start handling.
|
|
342
|
-
const declarations = [...document.querySelectorAll('input[type="checkbox"]')].filter(box => {
|
|
343
|
-
if (box.closest('#assistant-root,#assistant-journal') || box.disabled || !box.getClientRects().length)
|
|
344
|
-
return false;
|
|
345
|
-
const associated = [...(box.labels || []), ...document.querySelectorAll('label')].filter(label => label.contains(box) || (box.id && label.getAttribute('for') === box.id));
|
|
346
|
-
const text = [box.getAttribute('aria-label') || '', ...associated.map(label => label.textContent)].join(' ').replace(/\s+/g, ' ');
|
|
347
|
-
return /I confirm this is my own original work/i.test(text);
|
|
348
|
-
});
|
|
349
|
-
if (!startIssued) {
|
|
350
|
-
if (declarations.length !== 1)
|
|
351
|
-
throw Error('Could not uniquely identify the journal declaration checkbox. Start stopped.');
|
|
352
|
-
if (run !== generation || paused)
|
|
353
|
-
return;
|
|
354
|
-
status.textContent = 'Accepting the journal declaration and starting the assessment…';
|
|
355
|
-
notify();
|
|
356
|
-
if (!declarations[0].checked)
|
|
357
|
-
declarations[0].click();
|
|
358
|
-
await new Promise(resolve => setTimeout(resolve, 250));
|
|
359
|
-
if (run !== generation || paused)
|
|
360
|
-
return;
|
|
361
|
-
assertCurrentPage();
|
|
362
|
-
const starts = [...document.querySelectorAll('button')].filter(b => !b.closest('#assistant-root,#assistant-journal') && b.getClientRects().length && !b.disabled && b.getAttribute('aria-disabled') !== 'true' && /^(?:Start Assessment|Accept Terms to Start)$/i.test(b.textContent.trim()));
|
|
363
|
-
if (starts.length !== 1)
|
|
364
|
-
throw Error('Journal Start Assessment button is unavailable or ambiguous.');
|
|
365
|
-
startIssued = true;
|
|
366
|
-
starts[0].click();
|
|
367
|
-
}
|
|
368
|
-
for (let attempt = 0; attempt < 30; attempt++) {
|
|
369
|
-
if (run !== generation || paused)
|
|
370
|
-
return;
|
|
371
|
-
assertCurrentPage();
|
|
372
|
-
inputs = fields(document);
|
|
373
|
-
if (inputs)
|
|
374
|
-
break;
|
|
375
|
-
await new Promise(resolve => setTimeout(resolve, 500));
|
|
376
|
-
}
|
|
377
|
-
if (!inputs)
|
|
378
|
-
throw Error('The journal started, but all five writing fields did not appear. Submission stopped.');
|
|
379
|
-
}
|
|
380
|
-
finally {
|
|
381
|
-
if (run === generation)
|
|
382
|
-
starting = false;
|
|
383
|
-
}
|
|
344
|
+
const sections = Object.fromEntries(keys.map(key => [key, editors[key].editor.value]));
|
|
345
|
+
try {
|
|
346
|
+
validate(sections);
|
|
347
|
+
await navigator.clipboard.writeText(keys.map((key, index) => labels[index] + '\n' + sections[key].trim()).join('\n\n'));
|
|
348
|
+
status.textContent = 'Draft copied. Review, start and submit in the portal.';
|
|
384
349
|
}
|
|
385
|
-
|
|
350
|
+
catch (error) {
|
|
351
|
+
status.textContent = error.message || 'Could not copy the draft.';
|
|
352
|
+
}
|
|
353
|
+
notify();
|
|
354
|
+
});
|
|
355
|
+
preview.appendChild(copy);
|
|
356
|
+
async function prepareDraft() {
|
|
357
|
+
if (running || journalConfirmed)
|
|
386
358
|
return;
|
|
387
|
-
|
|
359
|
+
refreshInfo();
|
|
360
|
+
const notes = panel.querySelector('textarea').value.trim();
|
|
361
|
+
if (!info || !notes) {
|
|
362
|
+
status.textContent = !info ? 'Select the subject and module first.' : 'Add your own class experience and feelings to prepare a draft.';
|
|
363
|
+
notify();
|
|
388
364
|
return;
|
|
389
|
-
|
|
365
|
+
}
|
|
366
|
+
running = true;
|
|
367
|
+
global.BrowserAssistantJournalBusy = true;
|
|
368
|
+
button.disabled = true;
|
|
369
|
+
paused = false;
|
|
370
|
+
const run = ++generation;
|
|
371
|
+
status.textContent = 'Preparing the matching module journal…';
|
|
372
|
+
notify();
|
|
390
373
|
try {
|
|
391
|
-
validate(draft.sections);
|
|
392
|
-
if (!filled) {
|
|
393
|
-
// Existing complete text is adopted only by an explicit Start.
|
|
394
|
-
if (keys.some(k => readField(inputs[k]).trim()))
|
|
395
|
-
throw Error('Journal already contains text. Nothing was overwritten.');
|
|
396
|
-
for (const key of keys)
|
|
397
|
-
writeField(inputs[key], draft.sections[key]);
|
|
398
|
-
await new Promise(resolve => setTimeout(resolve, 700));
|
|
399
|
-
if (run !== generation)
|
|
400
|
-
return;
|
|
401
|
-
filled = true;
|
|
402
|
-
}
|
|
403
374
|
assertCurrentPage();
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
throw Error('The page did not retain all journal fields. Submission stopped.');
|
|
407
|
-
const count = validate(Object.fromEntries(keys.map(k => [k, readField(current[k])])));
|
|
408
|
-
const remaining = remainingSeconds(document);
|
|
409
|
-
if (remaining === null || remaining > 30 * 60) {
|
|
410
|
-
waitingForTimer = true;
|
|
411
|
-
const time = remaining === null ? 'Waiting for the portal timer to become readable.'
|
|
412
|
-
: `Current timer: ${formatJournalTime(remaining)}.`;
|
|
413
|
-
status.textContent = `${count} words ready. Waiting to submit at 30:00 remaining. ${time}`;
|
|
414
|
-
return;
|
|
415
|
-
}
|
|
416
|
-
if (paused)
|
|
417
|
-
return;
|
|
418
|
-
waitingForTimer = false;
|
|
419
|
-
if (remaining === 0)
|
|
420
|
-
throw Error('The portal timer expired. Check the journal status; no automatic click was sent.');
|
|
421
|
-
const candidates = [...document.querySelectorAll('button')].filter(b => !panel.contains(b) && b.getClientRects().length && !b.disabled && b.getAttribute('aria-disabled') !== 'true' && /^Submit Journal$/i.test(b.textContent.trim()));
|
|
422
|
-
if (candidates.length !== 1)
|
|
423
|
-
throw Error('Could not uniquely identify an enabled Submit Journal button. Content is filled; submit manually.');
|
|
424
|
-
// Consume the draft before clicking: observers must never submit twice.
|
|
425
|
-
draft = null;
|
|
426
|
-
candidates[0].click();
|
|
427
|
-
status.textContent = `${count} words filled. Submit clicked; checking the result…`;
|
|
428
|
-
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
375
|
+
activeRequest = new AbortController();
|
|
376
|
+
const response = await browserAssistantLocalInference('/journal', { ...info, notes }, message => chrome.runtime.sendMessage(message), activeRequest.signal);
|
|
429
377
|
if (run !== generation)
|
|
430
378
|
return;
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
379
|
+
assertCurrentPage();
|
|
380
|
+
if (!response?.ok) {
|
|
381
|
+
const detail = response?.data?.detail || response?.error;
|
|
382
|
+
throw Error(typeof detail === 'string' ? detail : detail?.message || 'Journal generation failed.');
|
|
383
|
+
}
|
|
384
|
+
validate(response.data.sections);
|
|
385
|
+
while (run === generation && paused)
|
|
386
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
436
387
|
if (run !== generation)
|
|
437
388
|
return;
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
389
|
+
assertCurrentPage();
|
|
390
|
+
for (const key of keys) {
|
|
391
|
+
const { editor, updateCount } = editors[key];
|
|
392
|
+
editor.value = response.data.sections[key];
|
|
393
|
+
updateCount();
|
|
394
|
+
}
|
|
395
|
+
preview.hidden = false;
|
|
396
|
+
idleState = 'REVIEW_DRAFT';
|
|
397
|
+
status.textContent = 'Draft ready. Edit the five sections, then review the declaration and start on the portal.';
|
|
443
398
|
}
|
|
444
399
|
catch (error) {
|
|
445
400
|
if (run === generation) {
|
|
446
|
-
draft = null;
|
|
447
|
-
filled = false;
|
|
448
|
-
waitingForTimer = false;
|
|
449
401
|
idleState = 'ERROR';
|
|
450
402
|
status.textContent = error.message;
|
|
451
403
|
}
|
|
452
404
|
}
|
|
453
405
|
finally {
|
|
454
406
|
if (run === generation) {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
button.disabled = false;
|
|
460
|
-
}
|
|
407
|
+
activeRequest = undefined;
|
|
408
|
+
running = false;
|
|
409
|
+
global.BrowserAssistantJournalBusy = false;
|
|
410
|
+
button.disabled = false;
|
|
461
411
|
notify();
|
|
462
412
|
}
|
|
463
413
|
}
|
|
464
414
|
}
|
|
465
|
-
button.addEventListener('click',
|
|
466
|
-
|
|
467
|
-
return;
|
|
468
|
-
try {
|
|
469
|
-
assertCurrentPage();
|
|
470
|
-
}
|
|
471
|
-
catch (error) {
|
|
472
|
-
status.textContent = error.message;
|
|
473
|
-
return;
|
|
474
|
-
}
|
|
475
|
-
refreshInfo();
|
|
476
|
-
const manualSubject = controls.querySelector('[data-subject]').value;
|
|
477
|
-
const manualNumber = controls.querySelector('[data-number]').value;
|
|
478
|
-
if (!controls.hidden && Boolean(manualSubject) !== Boolean(manualNumber)) {
|
|
479
|
-
status.textContent = 'For manual selection, choose both Subject and Module / Journal.';
|
|
480
|
-
return;
|
|
481
|
-
}
|
|
482
|
-
if (!info) {
|
|
483
|
-
status.textContent = 'Select both Subject and Module / Journal above, then click Fill & Submit Journal.';
|
|
484
|
-
return;
|
|
485
|
-
}
|
|
486
|
-
running = true;
|
|
487
|
-
global.BrowserAssistantJournalBusy = true;
|
|
488
|
-
submitting = false;
|
|
489
|
-
button.disabled = true;
|
|
490
|
-
idleState = 'READY';
|
|
491
|
-
paused = false;
|
|
492
|
-
filled = false;
|
|
493
|
-
waitingForTimer = false;
|
|
494
|
-
startIssued = false;
|
|
495
|
-
const run = ++generation;
|
|
496
|
-
status.textContent = 'Preparing the matching module journal…';
|
|
497
|
-
notify();
|
|
498
|
-
try {
|
|
499
|
-
const existingInputs = fields(document);
|
|
500
|
-
if (existingInputs && keys.some(key => readField(existingInputs[key]).trim())) {
|
|
501
|
-
const existingSections = Object.fromEntries(keys.map(key => [key, readField(existingInputs[key]).trim()]));
|
|
502
|
-
validate(existingSections);
|
|
503
|
-
draft = { sections: existingSections };
|
|
504
|
-
filled = true;
|
|
505
|
-
}
|
|
506
|
-
else {
|
|
507
|
-
const response = await chrome.runtime.sendMessage({ action: 'apiRequest', path: '/journal', body: { ...info, notes: panel.querySelector('textarea').value } });
|
|
508
|
-
if (run !== generation)
|
|
509
|
-
return;
|
|
510
|
-
assertCurrentPage();
|
|
511
|
-
if (!response?.ok) {
|
|
512
|
-
const detail = response?.data?.detail || response?.error || 'Journal generation failed.';
|
|
513
|
-
if (typeof detail === 'string' && detail.includes('Subject does not uniquely match the supplied syllabus')) {
|
|
514
|
-
throw Error('The running server could not match this subject. If you just added this syllabus, restart the updated server once, then try again. Otherwise check the selected subject. No journal was submitted.');
|
|
515
|
-
}
|
|
516
|
-
throw Error(typeof detail === 'string' ? detail : detail.message || 'Journal generation failed.');
|
|
517
|
-
}
|
|
518
|
-
validate(response.data.sections);
|
|
519
|
-
draft = response.data;
|
|
520
|
-
}
|
|
521
|
-
status.textContent = 'Content ready. Filling the journal, then waiting for 30:00 remaining before submission…';
|
|
522
|
-
notify();
|
|
523
|
-
await fillAndSubmit();
|
|
524
|
-
}
|
|
525
|
-
catch (error) {
|
|
526
|
-
if (run !== generation)
|
|
527
|
-
return;
|
|
528
|
-
draft = null;
|
|
529
|
-
filled = false;
|
|
530
|
-
waitingForTimer = false;
|
|
531
|
-
running = false;
|
|
532
|
-
idleState = 'ERROR';
|
|
533
|
-
global.BrowserAssistantJournalBusy = false;
|
|
534
|
-
button.disabled = false;
|
|
535
|
-
status.textContent = String(error.message);
|
|
536
|
-
notify();
|
|
537
|
-
}
|
|
538
|
-
});
|
|
415
|
+
button.addEventListener('click', event => { if (event.isTrusted)
|
|
416
|
+
void prepareDraft(); });
|
|
539
417
|
refreshInfo();
|
|
540
418
|
void loadCountdown();
|
|
541
419
|
void updateCountdown();
|
|
@@ -547,14 +425,6 @@ function browserAssistantJournal(global) {
|
|
|
547
425
|
clockObserver?.observe(document.body, { subtree: true, childList: true, characterData: true });
|
|
548
426
|
controller.mount(document.getElementById('assistant-journal-slot'));
|
|
549
427
|
document.dispatchEvent(new global.Event('assistant-journal-ready'));
|
|
550
|
-
try {
|
|
551
|
-
const pending = JSON.parse(sessionStorage.getItem('assistantPendingJournal') || 'null');
|
|
552
|
-
if (pending?.path === location.pathname && Date.now() - pending.createdAt < 300000) {
|
|
553
|
-
sessionStorage.removeItem('assistantPendingJournal');
|
|
554
|
-
button.click();
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
catch { /* Opening the journal without auto-start remains available. */ }
|
|
558
428
|
// Poll only the journal page; field discovery never changes platform restrictions.
|
|
559
429
|
const timer = setInterval(() => {
|
|
560
430
|
if (global.BrowserAssistantJournal?.current !== controller && global.BrowserAssistantJournal) {
|
|
@@ -562,7 +432,8 @@ function browserAssistantJournal(global) {
|
|
|
562
432
|
return;
|
|
563
433
|
}
|
|
564
434
|
if (!document.contains(panel) || storageKey !== `assistantJournal:${location.pathname}`) {
|
|
565
|
-
|
|
435
|
+
activeRequest?.abort();
|
|
436
|
+
generation++;
|
|
566
437
|
global.BrowserAssistantJournalBusy = false;
|
|
567
438
|
stopWatching();
|
|
568
439
|
panel.remove();
|
|
@@ -573,22 +444,6 @@ function browserAssistantJournal(global) {
|
|
|
573
444
|
void updateCountdown();
|
|
574
445
|
void recordJournalConfirmation();
|
|
575
446
|
notify();
|
|
576
|
-
if (draft && !submitting && !starting) {
|
|
577
|
-
const run = generation;
|
|
578
|
-
void fillAndSubmit().catch(error => {
|
|
579
|
-
if (run !== generation)
|
|
580
|
-
return;
|
|
581
|
-
draft = null;
|
|
582
|
-
filled = false;
|
|
583
|
-
waitingForTimer = false;
|
|
584
|
-
running = false;
|
|
585
|
-
idleState = 'ERROR';
|
|
586
|
-
global.BrowserAssistantJournalBusy = false;
|
|
587
|
-
button.disabled = false;
|
|
588
|
-
status.textContent = error.message;
|
|
589
|
-
notify();
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
447
|
}, 1000);
|
|
593
448
|
function stopWatching() {
|
|
594
449
|
clearInterval(timer);
|
|
@@ -602,13 +457,10 @@ if (typeof window !== 'undefined' && location.origin === 'https://admissions.aur
|
|
|
602
457
|
opening: false,
|
|
603
458
|
matches: () => /^\/modules\/(?:reflective-journal\/|assessments\/assessments\/?$)/.test(location.pathname),
|
|
604
459
|
active() { return this.current?.path === location.pathname ? this.current : null; },
|
|
605
|
-
getState() { return this.active()?.getState() || { state: this.opening ? 'OPENING_JOURNAL' : 'OPEN_JOURNAL', running: this.opening, completed: 0, message: '
|
|
460
|
+
getState() { return this.active()?.getState() || { state: this.opening ? 'OPENING_JOURNAL' : 'OPEN_JOURNAL', running: this.opening, completed: 0, message: 'Open the available ongoing journal to prepare a draft. If several are available, select its pencil button first.' }; },
|
|
606
461
|
mount(slot) { this.active()?.mount(slot); },
|
|
607
462
|
detach() { this.current?.detach(); },
|
|
608
|
-
stop() { this.active()?.stop(); this.opening = false;
|
|
609
|
-
sessionStorage.removeItem('assistantPendingJournal');
|
|
610
|
-
}
|
|
611
|
-
catch { } },
|
|
463
|
+
stop() { this.active()?.stop(); this.opening = false; },
|
|
612
464
|
pause() { this.active()?.pause(); },
|
|
613
465
|
start() {
|
|
614
466
|
if (this.active())
|
|
@@ -624,10 +476,6 @@ if (typeof window !== 'undefined' && location.origin === 'https://admissions.aur
|
|
|
624
476
|
&& /^\/modules\/reflective-journal\//.test(new URL(link.href, location.origin).pathname));
|
|
625
477
|
if (links.length === 1) {
|
|
626
478
|
this.opening = true;
|
|
627
|
-
try {
|
|
628
|
-
sessionStorage.setItem('assistantPendingJournal', JSON.stringify({ path: new URL(links[0].href, location.origin).pathname, createdAt: Date.now() }));
|
|
629
|
-
}
|
|
630
|
-
catch { }
|
|
631
479
|
links[0].click();
|
|
632
480
|
}
|
|
633
481
|
},
|
|
@@ -635,7 +483,7 @@ if (typeof window !== 'undefined' && location.origin === 'https://admissions.aur
|
|
|
635
483
|
if (!window.BrowserAssistantJournalListShortcut) {
|
|
636
484
|
window.BrowserAssistantJournalListShortcut = true;
|
|
637
485
|
document.addEventListener('keydown', event => {
|
|
638
|
-
if (!/^\/modules\/assessments\/assessments\/?$/.test(location.pathname) || !event.altKey || !event.shiftKey || event.ctrlKey || event.metaKey || event.repeat || event.isComposing)
|
|
486
|
+
if (!event.isTrusted || !/^\/modules\/assessments\/assessments\/?$/.test(location.pathname) || !event.altKey || !event.shiftKey || event.ctrlKey || event.metaKey || event.repeat || event.isComposing)
|
|
639
487
|
return;
|
|
640
488
|
if (event.code !== 'KeyJ' && String(event.key).toLowerCase() !== 'j')
|
|
641
489
|
return;
|
package/extension/manifest.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"manifest_version": 3,
|
|
3
3
|
"name": "Browser Assistant",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.9.0",
|
|
5
5
|
"description": "Scans webpages for MCQs and coding problems. Powered by Groq (cloud) and Ollama (local fallback).",
|
|
6
6
|
"permissions": [
|
|
7
7
|
"activeTab",
|
|
@@ -20,7 +20,9 @@
|
|
|
20
20
|
"content_scripts": [
|
|
21
21
|
{
|
|
22
22
|
"matches": [
|
|
23
|
-
"
|
|
23
|
+
"https://learning.ccbp.in/*",
|
|
24
|
+
"https://admissions.aurora.edu.in/*",
|
|
25
|
+
"http://127.0.0.1:8000/*"
|
|
24
26
|
],
|
|
25
27
|
"js": [
|
|
26
28
|
"automation-policy.js",
|
|
@@ -40,6 +42,13 @@
|
|
|
40
42
|
"host_permissions": [
|
|
41
43
|
"http://localhost:8000/*",
|
|
42
44
|
"http://127.0.0.1:8000/*",
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
+
"https://learning.ccbp.in/*",
|
|
46
|
+
"https://ide.ccbp.in/*",
|
|
47
|
+
"https://admissions.aurora.edu.in/*"
|
|
48
|
+
],
|
|
49
|
+
"commands": {
|
|
50
|
+
"toggle-automation": {
|
|
51
|
+
"description": "Start, pause or resume Browser Assistant automation"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
45
54
|
}
|
package/extension/popup.html
CHANGED
|
@@ -39,11 +39,6 @@
|
|
|
39
39
|
#server-status { color: #f59e0b; }
|
|
40
40
|
#server-status.online { color: #10b981; }
|
|
41
41
|
#server-status.offline { color: #ef4444; }
|
|
42
|
-
#journal-reminder { margin: 10px 0; font-size: 11px; }
|
|
43
|
-
#journal-reminder summary { cursor: pointer; }
|
|
44
|
-
#journal-reminder label { display: block; margin: 7px 0; }
|
|
45
|
-
#journal-reminder input { box-sizing: border-box; width: 100%; }
|
|
46
|
-
#journal-reminder-status { margin-top: 6px; }
|
|
47
42
|
</style>
|
|
48
43
|
</head>
|
|
49
44
|
<body>
|
|
@@ -51,25 +46,26 @@
|
|
|
51
46
|
<div class="logo-dot"></div>
|
|
52
47
|
<h3>Browser Assistant</h3>
|
|
53
48
|
</div>
|
|
54
|
-
<p>
|
|
49
|
+
<p>Open the assistant on the current webpage.</p>
|
|
50
|
+
<button id="open-assistant" type="button">Open on this tab</button>
|
|
55
51
|
<div class="status">Server: <span id="server-status">checking...</span></div>
|
|
56
52
|
<p id="journal-countdown" hidden></p>
|
|
57
|
-
<
|
|
58
|
-
<
|
|
59
|
-
<
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
</
|
|
53
|
+
<form id="local-pairing">
|
|
54
|
+
<label for="pairing-token">Local server token</label>
|
|
55
|
+
<input id="pairing-token" type="password" required autocomplete="off" spellcheck="false">
|
|
56
|
+
<button type="submit">Pair</button>
|
|
57
|
+
<button id="unpair-server" type="button">Forget</button>
|
|
58
|
+
</form>
|
|
59
|
+
<p>Run <code>python main.py --show-pairing-token</code> from the backend folder.</p>
|
|
60
|
+
<button id="check-provider" type="button">Check provider</button>
|
|
61
|
+
<p id="settings-status" role="status"></p>
|
|
62
|
+
<label><input id="save-history" type="checkbox"> Save scan history</label>
|
|
67
63
|
<div class="shortcuts">
|
|
68
64
|
<div class="shortcut-row"><span>Open panel</span> <kbd>`</kbd></div>
|
|
69
65
|
<div class="shortcut-row"><span>Close panel</span> <kbd>]</kbd></div>
|
|
70
66
|
<div class="shortcut-row"><span>Vision scan</span> <kbd>\</kbd></div>
|
|
71
67
|
<div class="shortcut-row"><span>Minimal mode</span> <kbd>[</kbd></div>
|
|
72
|
-
<div class="shortcut-row"><span>
|
|
68
|
+
<div class="shortcut-row"><span>Prepare journal</span> <kbd>Alt+Shift+J</kbd></div>
|
|
73
69
|
<div class="shortcut-row"><span>Automation start / pause / resume</span> <kbd>Alt+A</kbd></div>
|
|
74
70
|
</div>
|
|
75
71
|
<script src="popup.js"></script>
|