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. * scraper targets Torn's actual structure rather than guessing at selectors.
*/ */
const KNOWN_ATTRS = ['strength', 'defense', 'speed', 'dexterity', 'endurance', 'intelligence']; 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() { export function currentAttribute() {
const li = findActiveAttributeLi(); const li = findActiveAttributeLi();
@@ -66,16 +60,15 @@ function extractValueFromLi(li) {
} }
function findGymName() { function findGymName() {
// Gym names live in aria-labels of <button class="gymButton___HASH">. // Find the currently selected gym button. It has the "active" class.
const buttons = document.querySelectorAll('button[class*="gymButton"]'); const activeBtn = document.querySelector('button[class*="gymButton"][class*="active"]');
for (const btn of buttons) { if (activeBtn) {
const label = btn.getAttribute('aria-label') || ''; const label = activeBtn.getAttribute('aria-label') || '';
for (const name of KNOWN_GYMS) { // aria-label format: "<Gym Name>. Membership cost - $X. Energy usage - N per train."
// aria-label format: "Gym Name. Membership cost - $X. ..." // The gym name is everything before the first ". ".
if (label === name || label.startsWith(name + '.') || label.startsWith(name + ' ')) { const dot = label.indexOf('. ');
return name; if (dot !== -1) return label.slice(0, dot);
} return label; // no period, return whole label as fallback
}
} }
return null; return null;
} }