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() {
|
(async function() {
|
||||||
const rejectCheckbox = document.querySelector('#enable-reject');
|
function initCheckbox(selector, configName) {
|
||||||
chrome.storage.sync.get('enable_reject', (data) => {
|
const checkbox = document.querySelector(selector);
|
||||||
rejectCheckbox.checked = data.enable_reject;
|
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() {
|
||||||
rejectCheckbox.disabled = false;
|
conf = {}
|
||||||
|
conf[configName] = checkbox.checked;
|
||||||
|
await chrome.storage.sync.set(conf);
|
||||||
|
});
|
||||||
|
checkbox.disabled = false;
|
||||||
|
}
|
||||||
|
initCheckbox('#enable-reject', 'enable_reject');
|
||||||
|
initCheckbox('#enable-shrine', 'enable_shrine');
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -16,6 +16,13 @@
|
||||||
<input id="enable-reject" type="checkbox" disabled>
|
<input id="enable-reject" type="checkbox" disabled>
|
||||||
Enable fetching codes from rejectdopamine.com (3rd party service)
|
Enable fetching codes from rejectdopamine.com (3rd party service)
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
<input id="enable-shrine" type="checkbox" disabled>
|
||||||
|
Enable fetching codes from checkout.theshrine.net (3rd party service)
|
||||||
|
</label>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</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');
|
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) {
|
function codeTable(codes) {
|
||||||
const table = document.createElement('table');
|
const table = document.createElement('table');
|
||||||
table.innerHTML = '<thead><tr><th>Code</th><th>Score</th></tr></thead>';
|
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');
|
message('Warning: failed to fetch codes from reject');
|
||||||
} else {
|
} else {
|
||||||
const extraActivity = await rejectRes.json();
|
const extraActivity = await rejectRes.json();
|
||||||
for (const code of extraActivity.codes) {
|
mergeCodes(activity, extraActivity);
|
||||||
let found = false;
|
}
|
||||||
for (const code2 of activity.codes) {
|
}
|
||||||
if (code.code === code2.code) {
|
|
||||||
code2.score += code.score;
|
if (config.enable_shrine) {
|
||||||
found = true;
|
const shrineRes = await fetch(SERVER_URL + '/3p-proxy/shrine-checkout?' + query).catch((e) => {
|
||||||
break;
|
message(`Something went wrong: ${e}`);
|
||||||
}
|
console.error(e);
|
||||||
}
|
});
|
||||||
if (!found) {
|
if (!shrineRes.ok) {
|
||||||
activity.codes.push(code);
|
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