fix(main): anchor above Torn's properties___HASH list instead of looking for a form

This commit is contained in:
Claude Opus 4.8
2026-06-06 09:14:05 -05:00
committed by dev
parent ac1c04ecad
commit 429a5d1b14
+8 -14
View File
@@ -4,9 +4,14 @@ import { currentAttribute } from './dom.js';
import { startRequestInterceptor } from './interceptor.js';
function findAnchorElement() {
// Try several selectors in priority order. Torn's gym page structure
// varies; we cast a wide net and return the first match.
// Try several selectors in priority order. Torn's gym page renders the
// training UI as <ul class="properties___HASH"> (the list of attribute
// rows). Anchor the dialog above that list.
const candidates = [
'ul[class*="properties"]',
'[class*="gymContent"]',
'[class*="gymContentWrapper"]',
// Legacy fallbacks (kept in case Torn ever wraps the list in a form):
'form[action*="train"]',
'form.train-form',
'form[class*="train"]',
@@ -18,18 +23,7 @@ function findAnchorElement() {
];
for (const sel of candidates) {
const el = document.querySelector(sel);
if (el) {
// Prefer the form ancestor if the match is a button/link, since we
// want to anchor above the whole form, not just the button.
return el.closest('form') || el;
}
}
// Last-ditch: any element inside the gym panel that looks like the
// training form.
const panel = document.querySelector('.gym, #gym, [class*="gym-"], [class*="Gym"]');
if (panel) {
const form = panel.querySelector('form');
if (form) return form;
if (el) return el;
}
return null;
}