fix(dom): find active gym button by active class instead of iterating all buttons

This commit is contained in:
Claude Opus 4.8
2026-06-06 09:13:22 -05:00
committed by dev
parent 8d89e40b91
commit ac1c04ecad
+9 -16
View File
@@ -8,12 +8,6 @@
* scraper targets Torn's actual structure rather than guessing at selectors.
*/
const KNOWN_ATTRS = ['strength', 'defense', 'speed', 'dexterity', 'endurance', 'intelligence'];
const KNOWN_GYMS = [
'Total Bastion', 'Frontline Fitness', 'Premier Fitness', 'Average Joes',
"Woody's Workout Club", "Baldr's Gym", 'Sportscience Laboratory',
'Chrome Gym', "Mr. Miyagi's", 'Power House', 'Gym 300', 'Gym 400', 'Gym 500', 'Gym 600',
'Elite Gym', "David's Gym",
];
export function currentAttribute() {
const li = findActiveAttributeLi();
@@ -66,16 +60,15 @@ function extractValueFromLi(li) {
}
function findGymName() {
// Gym names live in aria-labels of <button class="gymButton___HASH">.
const buttons = document.querySelectorAll('button[class*="gymButton"]');
for (const btn of buttons) {
const label = btn.getAttribute('aria-label') || '';
for (const name of KNOWN_GYMS) {
// aria-label format: "Gym Name. Membership cost - $X. ..."
if (label === name || label.startsWith(name + '.') || label.startsWith(name + ' ')) {
return name;
}
}
// Find the currently selected gym button. It has the "active" class.
const activeBtn = document.querySelector('button[class*="gymButton"][class*="active"]');
if (activeBtn) {
const label = activeBtn.getAttribute('aria-label') || '';
// aria-label format: "<Gym Name>. Membership cost - $X. Energy usage - N per train."
// The gym name is everything before the first ". ".
const dot = label.indexOf('. ');
if (dot !== -1) return label.slice(0, dot);
return label; // no period, return whole label as fallback
}
return null;
}