-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.js
More file actions
70 lines (67 loc) · 2.47 KB
/
background.js
File metadata and controls
70 lines (67 loc) · 2.47 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Background script for Amigo Assignment Automator
chrome.runtime.onInstalled.addListener(function() {
console.log('Amigo Assignment Automator installed');
// Set default settings
chrome.storage.sync.set({
amigoSettings: {
autoSubmit: true,
randomAnswers: true,
skipEndModuleAssignments: true,
navigateContent: true,
navigateQuizzes: true,
isActive: false
}
});
});
// Handle messages from content scripts
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'toggleAutomation') {
// Handle automation toggle
sendResponse({ success: true });
} else if (request.action === 'amigo:all-done') {
try {
chrome.notifications.create('amigo_all_done', {
type: 'basic',
iconUrl: 'logo.png',
title: 'Amigo Automator',
message: 'Bot has processed all links, stopping now'
});
} catch (e) {
// ignore
}
sendResponse({ success: true });
} else if (request.action === 'amigo:export-answers') {
try {
const { courseName, assignmentName, payload } = request;
const safeCourse = (courseName || 'Unknown Course').replace(/[^a-z0-9\-_\s]/gi, '_').trim();
const safeAssignment = (assignmentName || 'Assignment').replace(/[^a-z0-9\-_\s]/gi, '_').trim();
const filename = `Database/${safeCourse}/${safeAssignment}.json`;
const blob = new Blob([JSON.stringify(payload, null, 2)], { type: 'application/json' });
const url = URL.createObjectURL(blob);
chrome.downloads.download({ url, filename, saveAs: false }, (downloadId) => {
if (chrome.runtime.lastError) {
sendResponse({ success: false, error: chrome.runtime.lastError.message });
} else {
sendResponse({ success: true, downloadId });
}
// Revoke after a short delay
setTimeout(() => URL.revokeObjectURL(url), 10000);
});
} catch (e) {
sendResponse({ success: false, error: String(e) });
}
return true;
}
});
// Handle tab updates to inject content script
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.status === 'complete' && tab.url) {
if (tab.url.includes('amigolms.amityonline.com')) {
// Content script will be automatically injected based on manifest
console.log('Amigo LMS page loaded');
} else if (tab.url.includes('s.amizone.net')) {
// Survey page loaded
console.log('Amizone survey page loaded');
}
}
});