feat(extension): capture activity information alongside code
This commit is contained in:
parent
7377e1bb95
commit
fe70b5692d
1 changed files with 36 additions and 6 deletions
|
@ -1,6 +1,22 @@
|
||||||
console.log('i am a background script');
|
console.log('i am a background script');
|
||||||
|
|
||||||
const codeCache = new Map();
|
const datastore = new Map();
|
||||||
|
|
||||||
|
function attachActivityDetails(activityId, date, time, name) {
|
||||||
|
if (datastore.has(activityId)) {
|
||||||
|
const activity = datastore.get(activityId);
|
||||||
|
activity.name = name;
|
||||||
|
activity.date = date;
|
||||||
|
activity.time = time;
|
||||||
|
} else {
|
||||||
|
datastore.set(activityId, {
|
||||||
|
date,
|
||||||
|
time,
|
||||||
|
name,
|
||||||
|
code: null,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function extractActivityId(url) {
|
function extractActivityId(url) {
|
||||||
const m = url.match(/^https:\/\/checkin\.york\.ac\.uk\/api\/selfregistration\/([0-9]+)\/present$/m);
|
const m = url.match(/^https:\/\/checkin\.york\.ac\.uk\/api\/selfregistration\/([0-9]+)\/present$/m);
|
||||||
|
@ -10,13 +26,18 @@ function extractActivityId(url) {
|
||||||
function interceptSubmit(details) {
|
function interceptSubmit(details) {
|
||||||
const activityId = extractActivityId(details.url);
|
const activityId = extractActivityId(details.url);
|
||||||
const codeCorrect = details.statusCode >= 200 && details.statusCode <= 299;
|
const codeCorrect = details.statusCode >= 200 && details.statusCode <= 299;
|
||||||
if (!codeCache.has(activityId)) {
|
if (!datastore.has(activityId)) {
|
||||||
console.error('we did not manage to log a code for activity', activityId);
|
console.error('we do not have information about the activity', activityId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const code = codeCache.get(activityId);
|
const activity = datastore.get(activityId);
|
||||||
codeCache.delete(activityId);
|
if (!activity.date || !activity.time || !activity.name || !activity.code) {
|
||||||
|
console.error('we do not have all the information about the activity', activityId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
console.log('request for activity', activityId, 'the code', code, 'was', codeCorrect ? 'correct' : 'incorrect');
|
console.log('request for activity', activityId, 'the code', code, 'was', codeCorrect ? 'correct' : 'incorrect');
|
||||||
|
// TODO: Send data to server.
|
||||||
}
|
}
|
||||||
|
|
||||||
function interceptCode(details) {
|
function interceptCode(details) {
|
||||||
|
@ -35,7 +56,16 @@ function interceptCode(details) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const code = body.formData['code'][0];
|
const code = body.formData['code'][0];
|
||||||
codeCache.set(activityId, code);
|
if (datastore.has(activityId)) {
|
||||||
|
datastore.get(activityId).code = code;
|
||||||
|
} else {
|
||||||
|
datastore.set(activityId, {
|
||||||
|
date: null,
|
||||||
|
time: null,
|
||||||
|
name: null,
|
||||||
|
code,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
browser.webRequest.onBeforeRequest.addListener(interceptCode, {
|
browser.webRequest.onBeforeRequest.addListener(interceptCode, {
|
||||||
|
|
Loading…
Reference in a new issue