feat(extension): initial commit

This commit is contained in:
Ashhhleyyy 2024-02-16 12:42:44 +00:00
commit e020bcebec
Signed by: ash
GPG key ID: 83B789081A0878FB
3 changed files with 70 additions and 0 deletions

23
extension/manifest.json Normal file
View file

@ -0,0 +1,23 @@
{
"manifest_version":2,
"name": "aci",
"version": "0.0.1",
"description": "aci",
"content_scripts":[
{
"matches": ["*://checkin.york.ac.uk/selfregistration"],
"js": ["src/content.js"]
}
],
"permissions": [
"webRequest",
"*://aci-api.ashhhleyyy.dev/*",
"*://checkin.york.ac.uk/*"
],
"background": {
"scripts": ["src/background.js"],
"persistent": false,
"type": "module"
}
}

View file

@ -0,0 +1,46 @@
console.log('i am a background script');
const codeCache = new Map();
function extractActivityId(url) {
const m = url.match(/^https:\/\/checkin\.york\.ac\.uk\/api\/selfregistration\/([0-9]+)\/present$/m);
return m[1];
}
function interceptSubmit(details) {
const activityId = extractActivityId(details.url);
const codeCorrect = details.statusCode >= 200 && details.statusCode <= 299;
if (!codeCache.has(activityId)) {
console.error('we did not manage to log a code for activity', activityId);
return;
}
const code = codeCache.get(activityId);
codeCache.delete(activityId);
console.log('request for activity', activityId, 'the code', code, 'was', codeCorrect ? 'correct' : 'incorrect');
}
function interceptCode(details) {
const activityId = extractActivityId(details.url);
const body = details.requestBody;
if (body.error) {
console.error('failed to obtain request body', body.error);
return;
}
if (!body.formData) {
console.error('request body did not have form data');
return;
}
if (!body.formData['code']) {
console.error('request did not contain a code');
return;
}
const code = body.formData['code'][0];
codeCache.set(activityId, code);
}
browser.webRequest.onBeforeRequest.addListener(interceptCode, {
urls: ['https://checkin.york.ac.uk/api/selfregistration/*/present'],
}, ['requestBody']);
browser.webRequest.onCompleted.addListener(interceptSubmit, {
urls: ['https://checkin.york.ac.uk/api/selfregistration/*/present'],
});

1
extension/src/content.js Normal file
View file

@ -0,0 +1 @@
console.log('hello');