Skip to content

Commit 7ae50a2

Browse files
Completely migrate over to API v2 for personalstats. (#833)
* Completely migrate over to API v2 for personalstats. * Adjust achievements for crimes 2. * Include some missing achievements like hospitals and jail visits and special ammo. * Improve page detection on 'loader.php'.
1 parent 672ba4d commit 7ae50a2

File tree

12 files changed

+2555
-2757
lines changed

12 files changed

+2555
-2757
lines changed

extension/changelog.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
{ "message": "Better note about external services.", "contributor": "DeKleineKobini" },
2525
{ "message": "Show FF scouter gauge on more pages when honor bars are disabled.", "contributor": "DeKleineKobini" },
2626
{ "message": "Filter on any weapon bonus in the faction armory.", "contributor": "DeKleineKobini" },
27-
{ "message": "Add a button to force update your userdata.", "contributor": "DeKleineKobini" }
27+
{ "message": "Add a button to force update your userdata.", "contributor": "DeKleineKobini" },
28+
{ "message": "Completely migrate over to API v2 for personalstats.", "contributor": "DeKleineKobini" },
29+
{ "message": "Adjust achievements for crimes 2.", "contributor": "DeKleineKobini" },
30+
{ "message": "Include some missing achievements like hospitals and jail visits and special ammo.", "contributor": "DeKleineKobini" },
31+
{ "message": "Improve page detection on 'loader.php'.", "contributor": "DeKleineKobini" }
2832
],
2933
"removed": []
3034
}

extension/pages/settings/settings.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,6 @@ <h2>
333333
<input id="api_usage-user_refills" type="checkbox" />
334334
<label for="api_usage-user_refills">Refills</label>
335335
</div>
336-
<div class="option">
337-
<input id="api_usage-user_personalstats" type="checkbox" />
338-
<label for="api_usage-user_personalstats">Personal Stats</label>
339-
</div>
340336
<div class="option">
341337
<input id="api_usage-user_stocks" type="checkbox" />
342338
<label for="api_usage-user_stocks">Stocks</label>
@@ -416,6 +412,10 @@ <h2>
416412
<input id="api_usage-userV2_organizedcrime" type="checkbox" />
417413
<label for="api_usage-userV2_organizedcrime">Organized Crime</label>
418414
</div>
415+
<div class="option">
416+
<input id="api_usage-userV2_personalstats" type="checkbox" />
417+
<label for="api_usage-userV2_personalstats">Personal Stats</label>
418+
</div>
419419
</section>
420420
<section name="chat">
421421
<div class="header">Chat</div>

extension/scripts/background.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,11 @@ async function convertDatabase() {
329329
newStorage.settings.pages.global.reviveProvider = "";
330330
}
331331
updated = true;
332+
} else if (version <= toNumericVersion("7.4.3")) {
333+
if (storage?.settings?.apiUsage?.userV2?.personalstats === false) {
334+
newStorage.settings.apiUsage.userV2.personalstats = false;
335+
}
336+
updated = true;
332337
}
333338

334339
const newVersion = chrome.runtime.getManifest().version;
@@ -514,7 +519,6 @@ async function updateUserdata(forceUpdate = false) {
514519
}
515520
if (updateBasic) {
516521
for (const selection of [
517-
"personalstats",
518522
"stocks",
519523
// "inventory",
520524
"merits",
@@ -534,7 +538,7 @@ async function updateUserdata(forceUpdate = false) {
534538

535539
selections.push(selection);
536540
}
537-
for (const selection of ["organizedcrime"]) {
541+
for (const selection of ["organizedcrime", "personalstats"]) {
538542
if (!settings.apiUsage.userV2[selection]) continue;
539543

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

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

559563
userdata = {
560564
...newUserdata,
@@ -620,9 +624,13 @@ async function updateUserdata(forceUpdate = false) {
620624
}
621625

622626
if (oldUserdata.personalstats && userdata.personalstats) {
623-
const fetchData = ["killstreak", "defendsstalemated", "attacksdraw", "defendslost"].some(
624-
(stat) => oldUserdata.personalstats[stat] !== userdata.personalstats[stat]
625-
);
627+
const fetchData = [
628+
(data) => data.personalstats.attacking.attacks.lost,
629+
(data) => data.personalstats.attacking.attacks.stalemate,
630+
(data) => data.personalstats.attacking.defends.lost,
631+
(data) => data.personalstats.attacking.defends.stalemate,
632+
(data) => data.personalstats.attacking.killstreak.current,
633+
].some((getter) => getter(oldUserdata) !== getter(userdata));
626634

627635
await ttStorage.change({ attackHistory: { fetchData } });
628636
}
@@ -2004,7 +2012,7 @@ async function setupAudioPlayerDocument() {
20042012
});
20052013

20062014
try {
2007-
if (existingContexts.length == 0) {
2015+
if (existingContexts.length === 0) {
20082016
await chrome.offscreen.createDocument({
20092017
url: offscreenURL,
20102018
reasons: ["AUDIO_PLAYBACK"],

0 commit comments

Comments
 (0)