Skip to content

Commit

Permalink
Check whether your data is corrupted on the about page. (#834)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeKleineKobini authored Feb 7, 2025
1 parent c835763 commit 34079f4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion extension/changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
{ "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" }
{ "message": "Improve page detection on 'loader.php'.", "contributor": "DeKleineKobini" },
{ "message": "Check whether your data is corrupted on the about page.", "contributor": "DeKleineKobini" }
],
"removed": []
}
Expand Down
8 changes: 8 additions & 0 deletions extension/pages/settings/about.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,11 @@ body.dark #about a {
border: none;
border-bottom: 1px solid #aaa;
}

.corruption-okay {
color: greenyellow;
}

.corruption-error {
color: red;
}
18 changes: 18 additions & 0 deletions extension/pages/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -2007,6 +2007,24 @@ <h2>About</h2>
<span class="note">Estimation of the stored data, not the extension files.</span>
</p>
</section>
<section>
<p class="mt10">
<strong>Userdata:</strong>
<span id="userdata-corruption">checking...</span>
</p>
<p>
<strong>Torndata:</strong>
<span id="torndata-corruption">checking...</span>
</p>
<p>
<strong>Stockdata:</strong>
<span id="stockdata-corruption">checking...</span>
</p>
<p>
<strong>Factiondata:</strong>
<span id="factiondata-corruption">checking...</span>
</p>
</section>
<section>
<p>
Our source code is available on <a href="https://github.com/Mephiles/torntools_extension" target="_blank">Github</a> and licenced under the
Expand Down
22 changes: 22 additions & 0 deletions extension/pages/settings/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1825,6 +1825,12 @@ function setupAbout() {
// version
about.find(".version").textContent = chrome.runtime.getManifest().version;

// data corruption
showCorruption("userdata-corruption", () => typeof userdata === "object" && Object.keys(userdata).length > 5);
showCorruption("torndata-corruption", () => typeof torndata === "object" && typeof torndata.items === "object" && Object.keys(torndata.items).length > 5);
showCorruption("stockdata-corruption", () => typeof stockdata === "object" && Object.keys(stockdata).length > 5);
showCorruption("factiondata-corruption", () => typeof factiondata === "object" && typeof factiondata.access === "string");

// disk space
ttStorage.getSize().then((size) => (about.find(".disk-space").textContent = formatBytes(size)));

Expand Down Expand Up @@ -1872,6 +1878,22 @@ function setupAbout() {
ourTeam.appendChild(card);
}
}

function showCorruption(id, checkFunction) {
const element = about.find(`#${id}`);
if (!element) return;

const status = checkFunction();

element.classList.remove("corruption-okay", "corruption-error");
if (status) {
element.textContent = "likely okay";
element.classList.add("corruption-okay");
} else {
element.textContent = "possibly corrupted";
element.classList.add("corruption-error");
}
}
}

function formatBytes(bytes, options = {}) {
Expand Down

0 comments on commit 34079f4

Please sign in to comment.