feat(extension): support fetching codes from checkout.theshrine.net via proxy
All checks were successful
Build extension ZIP / Build extension (push) Successful in 46s
All checks were successful
Build extension ZIP / Build extension (push) Successful in 46s
This commit is contained in:
parent
8c553b92f4
commit
e626ff5eae
3 changed files with 55 additions and 23 deletions
|
@ -1,12 +1,16 @@
|
|||
(async function() {
|
||||
const rejectCheckbox = document.querySelector('#enable-reject');
|
||||
chrome.storage.sync.get('enable_reject', (data) => {
|
||||
rejectCheckbox.checked = data.enable_reject;
|
||||
function initCheckbox(selector, configName) {
|
||||
const checkbox = document.querySelector(selector);
|
||||
chrome.storage.sync.get(configName, (data) => {
|
||||
checkbox.checked = data[configName];
|
||||
});
|
||||
rejectCheckbox.addEventListener('change', async function() {
|
||||
await chrome.storage.sync.set({
|
||||
enable_reject: rejectCheckbox.checked,
|
||||
checkbox.addEventListener('change', async function() {
|
||||
conf = {}
|
||||
conf[configName] = checkbox.checked;
|
||||
await chrome.storage.sync.set(conf);
|
||||
});
|
||||
});
|
||||
rejectCheckbox.disabled = false;
|
||||
checkbox.disabled = false;
|
||||
}
|
||||
initCheckbox('#enable-reject', 'enable_reject');
|
||||
initCheckbox('#enable-shrine', 'enable_shrine');
|
||||
})();
|
||||
|
|
|
@ -16,6 +16,13 @@
|
|||
<input id="enable-reject" type="checkbox" disabled>
|
||||
Enable fetching codes from rejectdopamine.com (3rd party service)
|
||||
</label>
|
||||
|
||||
<br>
|
||||
|
||||
<label>
|
||||
<input id="enable-shrine" type="checkbox" disabled>
|
||||
Enable fetching codes from checkout.theshrine.net (3rd party service)
|
||||
</label>
|
||||
</main>
|
||||
</div>
|
||||
</body>
|
||||
|
|
|
@ -1,6 +1,26 @@
|
|||
chrome.storage.sync.get(['enable_reject'], async function(config) {
|
||||
chrome.storage.sync.get([
|
||||
'enable_reject',
|
||||
'enable_shrine'
|
||||
], async function(config) {
|
||||
const root = document.querySelector('#root');
|
||||
|
||||
function mergeCodes(activity, extraActivity) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function codeTable(codes) {
|
||||
const table = document.createElement('table');
|
||||
table.innerHTML = '<thead><tr><th>Code</th><th>Score</th></tr></thead>';
|
||||
|
@ -113,19 +133,20 @@ chrome.storage.sync.get(['enable_reject'], async function(config) {
|
|||
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);
|
||||
mergeCodes(activity, extraActivity);
|
||||
}
|
||||
}
|
||||
|
||||
if (config.enable_shrine) {
|
||||
const shrineRes = await fetch(SERVER_URL + '/3p-proxy/shrine-checkout?' + query).catch((e) => {
|
||||
message(`Something went wrong: ${e}`);
|
||||
console.error(e);
|
||||
});
|
||||
if (!shrineRes.ok) {
|
||||
message('Warning: failed to fetch codes from checkout.theshrine.net');
|
||||
} else {
|
||||
const extraActivity = await shrineRes.json();
|
||||
mergeCodes(activity, extraActivity);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue