feat(extension): support fetching codes from reject via proxy
This commit is contained in:
parent
238961799d
commit
0bee055a14
5 changed files with 70 additions and 5 deletions
|
@ -11,6 +11,7 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"permissions": [
|
"permissions": [
|
||||||
|
"storage",
|
||||||
"webRequest",
|
"webRequest",
|
||||||
"*://aci-api.ashhhleyyy.dev/*",
|
"*://aci-api.ashhhleyyy.dev/*",
|
||||||
"*://checkin.york.ac.uk/*"
|
"*://checkin.york.ac.uk/*"
|
||||||
|
@ -22,6 +23,9 @@
|
||||||
"browser_action": {
|
"browser_action": {
|
||||||
"default_popup": "src/popup.html"
|
"default_popup": "src/popup.html"
|
||||||
},
|
},
|
||||||
|
"options_ui": {
|
||||||
|
"page": "src/config.html"
|
||||||
|
},
|
||||||
"browser_specific_settings": {
|
"browser_specific_settings": {
|
||||||
"gecko": {
|
"gecko": {
|
||||||
"update_url": "https://git.ashhhleyyy.dev/ash/aci/raw/branch/main/addon_updates.json",
|
"update_url": "https://git.ashhhleyyy.dev/ash/aci/raw/branch/main/addon_updates.json",
|
||||||
|
|
12
extension/src/config-page.js
Normal file
12
extension/src/config-page.js
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
(async function() {
|
||||||
|
const rejectCheckbox = document.querySelector('#enable-reject');
|
||||||
|
chrome.storage.sync.get('enable_reject', (data) => {
|
||||||
|
rejectCheckbox.checked = data.enable_reject;
|
||||||
|
});
|
||||||
|
rejectCheckbox.addEventListener('change', async function() {
|
||||||
|
await chrome.storage.sync.set({
|
||||||
|
enable_reject: rejectCheckbox.checked,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
rejectCheckbox.disabled = false;
|
||||||
|
})();
|
22
extension/src/config.html
Normal file
22
extension/src/config.html
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||||
|
<title>Checkin Codes</title>
|
||||||
|
<meta name="description" content="">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link rel="stylesheet" href="ash.css">
|
||||||
|
<script src="config-page.js" defer></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="page-container">
|
||||||
|
<main class="content" id="root">
|
||||||
|
<label>
|
||||||
|
<input id="enable-reject" type="checkbox" disabled>
|
||||||
|
Enable fetching codes from rejectdopamine.com (3rd party service)
|
||||||
|
</label>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -1,2 +1,2 @@
|
||||||
this.SERVER_URL = 'https://aci-api.ashhhleyyy.dev';
|
//this.SERVER_URL = 'https://aci-api.ashhhleyyy.dev';
|
||||||
//this.SERVER_URL = 'http://localhost:8000';
|
this.SERVER_URL = 'http://localhost:8000';
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
(async function() {
|
chrome.storage.sync.get(['enable_reject'], async function(config) {
|
||||||
const root = document.querySelector('#root');
|
const root = document.querySelector('#root');
|
||||||
|
|
||||||
function codeTable(codes) {
|
function codeTable(codes) {
|
||||||
|
@ -97,12 +97,39 @@
|
||||||
message(`Something went wrong: ${e}`);
|
message(`Something went wrong: ${e}`);
|
||||||
console.error(e);
|
console.error(e);
|
||||||
});
|
});
|
||||||
removeLoading();
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
|
removeLoading();
|
||||||
message('Server returned error code ' + res.status + ': ' + res.statusText, true);
|
message('Server returned error code ' + res.status + ': ' + res.statusText, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const activity = await res.json();
|
const activity = await res.json();
|
||||||
|
|
||||||
|
if (config.enable_reject) {
|
||||||
|
const rejectRes = await fetch(SERVER_URL + '/3p-proxy/reject?' + query).catch((e) => {
|
||||||
|
message(`Something went wrong: ${e}`);
|
||||||
|
console.error(e);
|
||||||
|
});
|
||||||
|
if (!rejectRes.ok) {
|
||||||
|
message('Warning: failed to fetch codes from reject');
|
||||||
|
} else {
|
||||||
|
const extraActivity = await rejectRes.json();
|
||||||
|
for (const code of extraActivity.codes) {
|
||||||
|
let found = false;
|
||||||
|
for (const code2 of activity.codes) {
|
||||||
|
if (code.code === code2.code) {
|
||||||
|
code2.score += code.score;
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
activity.codes.push(code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
removeLoading();
|
||||||
if (activity.codes.length === 0) {
|
if (activity.codes.length === 0) {
|
||||||
message('No codes are available right now :/');
|
message('No codes are available right now :/');
|
||||||
} else {
|
} else {
|
||||||
|
@ -133,4 +160,4 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})();
|
});
|
||||||
|
|
Loading…
Reference in a new issue