Skip to content

Commit

Permalink
Fix Disable Gym Stats when switching gyms.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sashank999 committed Jul 9, 2024
1 parent 2bf5589 commit 62196dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion extension/changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"version": { "major": 7, "minor": 4, "build": 0 },
"title": "Beta",
"date": false,
"logs": { "features": [], "fixes": [], "changes": [], "removed": [] }
"logs": {
"features": [],
"fixes": [{ "message": "Fix Disable Gym Stats when switching gyms.", "contributor": "TheFoxMan" }],
"changes": [],
"removed": []
}
},
{
"version": { "major": 7, "minor": 3, "build": 1 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
new MutationObserver(async (mutations) => {
if (!feature.enabled()) return;

if (mutations.some((mutation) => [...mutation?.addedNodes].some((node) => node.className.includes("gymContentWrapper__")))) {
if (mutations.some((mutation) => [...mutation?.addedNodes].some((node) => node.className.includes?.("gymContentWrapper__")))) {

This comment has been minimized.

Copy link
@cubis

cubis Jul 24, 2024

Should this maybe be using node.className.contains

This comment has been minimized.

Copy link
@Kwack-Kwack

Kwack-Kwack Jul 24, 2024

Contributor

Not unless I'm missing something?
I think you're thinking of node.classList.contains(...), however node.className gets the attribute as a string. Since we don't know the full class name, the two options are either this or node.matches([class*='gymContentWrapper__'])

This comment has been minimized.

Copy link
@cubis

cubis Jul 24, 2024

I see. Maybe your alternative is better.

On my older PC, I noticed a chrome console error everytime I clicked the Train button: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'includes') but actually this may be due to the className property itself not being defined now that I think about it a bit more.

In the contribution document it says that we shouldn't use Optional Chaining:
https://github.com/Mephiles/torntools_extension/blob/master/CONTRIBUTING.md

All code should work on as much browsers as possible.
Optional Chaining isn't supported by Kiwi Browser.

However, if optional chaining is going to be used, perhaps go one step further with node.className?.includes?.

This comment has been minimized.

Copy link
@Sashank999

Sashank999 Jul 26, 2024

Author Collaborator

Kiwi Browser previously did not support optional chhaining as it was using an older snapshot of Chromium codebase. It now works on Kiwi Browser too.

I don't have any errors when training, even before and after disabling a stat and switching gyms. I suggest you update your browser.

showCheckboxes();

requireElement("#gymroot ul[class*='properties_']").then((properties) => {
Expand All @@ -58,7 +58,7 @@
async function showCheckboxes() {
await sleep();

const properties = await requireElement("#gymroot ul[class*='properties___']");
const properties = (await requireElement("#gymroot ul[class*='properties___'] [class*='strength___']")).closest("#gymroot ul[class*='properties___']");

for (const stat of properties.findAll(":scope > li:not([class*='locked___']):not(.tt-modified)")) {
stat.classList.add("tt-modified");
Expand Down

0 comments on commit 62196dd

Please sign in to comment.