Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completely migrate over to API v2 for personalstats. #833

Merged
merged 2 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion extension/changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
{ "message": "Better note about external services.", "contributor": "DeKleineKobini" },
{ "message": "Show FF scouter gauge on more pages when honor bars are disabled.", "contributor": "DeKleineKobini" },
{ "message": "Filter on any weapon bonus in the faction armory.", "contributor": "DeKleineKobini" },
{ "message": "Add a button to force update your userdata.", "contributor": "DeKleineKobini" }
{ "message": "Add a button to force update your userdata.", "contributor": "DeKleineKobini" },
{ "message": "Completely migrate over to API v2 for personalstats.", "contributor": "DeKleineKobini" },
{ "message": "Adjust achievements for crimes 2.", "contributor": "DeKleineKobini" },
{ "message": "Include some missing achievements like hospitals and jail visits and special ammo.", "contributor": "DeKleineKobini" },
{ "message": "Improve page detection on 'loader.php'.", "contributor": "DeKleineKobini" }
],
"removed": []
}
Expand Down
8 changes: 4 additions & 4 deletions extension/pages/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,6 @@ <h2>
<input id="api_usage-user_refills" type="checkbox" />
<label for="api_usage-user_refills">Refills</label>
</div>
<div class="option">
<input id="api_usage-user_personalstats" type="checkbox" />
<label for="api_usage-user_personalstats">Personal Stats</label>
</div>
<div class="option">
<input id="api_usage-user_stocks" type="checkbox" />
<label for="api_usage-user_stocks">Stocks</label>
Expand Down Expand Up @@ -416,6 +412,10 @@ <h2>
<input id="api_usage-userV2_organizedcrime" type="checkbox" />
<label for="api_usage-userV2_organizedcrime">Organized Crime</label>
</div>
<div class="option">
<input id="api_usage-userV2_personalstats" type="checkbox" />
<label for="api_usage-userV2_personalstats">Personal Stats</label>
</div>
</section>
<section name="chat">
<div class="header">Chat</div>
Expand Down
22 changes: 15 additions & 7 deletions extension/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ async function convertDatabase() {
newStorage.settings.pages.global.reviveProvider = "";
}
updated = true;
} else if (version <= toNumericVersion("7.4.3")) {
if (storage?.settings?.apiUsage?.userV2?.personalstats === false) {
newStorage.settings.apiUsage.userV2.personalstats = false;
}
updated = true;
}

const newVersion = chrome.runtime.getManifest().version;
Expand Down Expand Up @@ -514,7 +519,6 @@ async function updateUserdata(forceUpdate = false) {
}
if (updateBasic) {
for (const selection of [
"personalstats",
"stocks",
// "inventory",
"merits",
Expand All @@ -534,7 +538,7 @@ async function updateUserdata(forceUpdate = false) {

selections.push(selection);
}
for (const selection of ["organizedcrime"]) {
for (const selection of ["organizedcrime", "personalstats"]) {
if (!settings.apiUsage.userV2[selection]) continue;

selectionsV2.push(selection);
Expand All @@ -554,7 +558,7 @@ async function updateUserdata(forceUpdate = false) {

const oldUserdata = { ...userdata };
const newUserdata = selections.length ? await fetchData("torn", { section: "user", selections }) : {};
const newUserdataV2 = selectionsV2.length ? await fetchData("tornv2", { section: "user", selections: selectionsV2 }) : {};
const newUserdataV2 = selectionsV2.length ? await fetchData("tornv2", { section: "user", selections: selectionsV2, params: { cat: "all" } }) : {};

userdata = {
...newUserdata,
Expand Down Expand Up @@ -620,9 +624,13 @@ async function updateUserdata(forceUpdate = false) {
}

if (oldUserdata.personalstats && userdata.personalstats) {
const fetchData = ["killstreak", "defendsstalemated", "attacksdraw", "defendslost"].some(
(stat) => oldUserdata.personalstats[stat] !== userdata.personalstats[stat]
);
const fetchData = [
(data) => data.personalstats.attacking.attacks.lost,
(data) => data.personalstats.attacking.attacks.stalemate,
(data) => data.personalstats.attacking.defends.lost,
(data) => data.personalstats.attacking.defends.stalemate,
(data) => data.personalstats.attacking.killstreak.current,
].some((getter) => getter(oldUserdata) !== getter(userdata));

await ttStorage.change({ attackHistory: { fetchData } });
}
Expand Down Expand Up @@ -2004,7 +2012,7 @@ async function setupAudioPlayerDocument() {
});

try {
if (existingContexts.length == 0) {
if (existingContexts.length === 0) {
await chrome.offscreen.createDocument({
url: offscreenURL,
reasons: ["AUDIO_PLAYBACK"],
Expand Down
Loading