fix(main): anchor above Torn's properties___HASH list instead of looking for a form
This commit is contained in:
+8
-14
@@ -4,9 +4,14 @@ import { currentAttribute } from './dom.js';
|
|||||||
import { startRequestInterceptor } from './interceptor.js';
|
import { startRequestInterceptor } from './interceptor.js';
|
||||||
|
|
||||||
function findAnchorElement() {
|
function findAnchorElement() {
|
||||||
// Try several selectors in priority order. Torn's gym page structure
|
// Try several selectors in priority order. Torn's gym page renders the
|
||||||
// varies; we cast a wide net and return the first match.
|
// training UI as <ul class="properties___HASH"> (the list of attribute
|
||||||
|
// rows). Anchor the dialog above that list.
|
||||||
const candidates = [
|
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[action*="train"]',
|
||||||
'form.train-form',
|
'form.train-form',
|
||||||
'form[class*="train"]',
|
'form[class*="train"]',
|
||||||
@@ -18,18 +23,7 @@ function findAnchorElement() {
|
|||||||
];
|
];
|
||||||
for (const sel of candidates) {
|
for (const sel of candidates) {
|
||||||
const el = document.querySelector(sel);
|
const el = document.querySelector(sel);
|
||||||
if (el) {
|
if (el) return 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;
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user