feat(main): anchor dialog by inserting before gymContentWrapper (dock in page flow)
This commit is contained in:
+10
-17
@@ -4,20 +4,20 @@ 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 renders the
|
// Return the element to insert the dialog BEFORE in the DOM.
|
||||||
// training UI as <ul class="properties___HASH"> (the list of attribute
|
// The user wants the dialog between the notification wrapper and the
|
||||||
// rows). Anchor the dialog above that list.
|
// gym content wrapper; we insert before gymContentWrapper.
|
||||||
const candidates = [
|
const candidates = [
|
||||||
'ul[class*="properties"]',
|
'[class*="gymContentWrapper"]', // outer wrapper — best insertion point
|
||||||
'[class*="gymContent"]',
|
'[class*="gymContent"]', // inner wrapper (fallback)
|
||||||
'[class*="gymContentWrapper"]',
|
'ul[class*="properties"]', // the list itself (last resort)
|
||||||
// Legacy fallbacks (kept in case Torn ever wraps the list in a form):
|
// Legacy fallbacks (kept for robustness):
|
||||||
'form[action*="train"]',
|
'form[action*="train"]',
|
||||||
'form.train-form',
|
'form.train-form',
|
||||||
'form[class*="train"]',
|
'form[class*="train"]',
|
||||||
'[class*="train-button"]',
|
'[class*="train-button"]',
|
||||||
'button[class*="train"]',
|
'button[class*="train"]',
|
||||||
'a[class*="train"]',
|
'a[href*="train"]',
|
||||||
'button[name="train"]',
|
'button[name="train"]',
|
||||||
'a[href*="train"]',
|
'a[href*="train"]',
|
||||||
];
|
];
|
||||||
@@ -99,20 +99,13 @@ function start() {
|
|||||||
if (prefs.mode === 'anchored') {
|
if (prefs.mode === 'anchored') {
|
||||||
const el = findAnchorElement();
|
const el = findAnchorElement();
|
||||||
if (el) {
|
if (el) {
|
||||||
const rect = el.getBoundingClientRect();
|
dialog.setMode('anchored', { canAnchor: true, insertBefore: el });
|
||||||
dialog.setMode('anchored', { canAnchor: true, rect: rect });
|
|
||||||
if (typeof ResizeObserver !== 'undefined') {
|
|
||||||
const ro = new ResizeObserver(function () {
|
|
||||||
if (prefs.mode === 'anchored') dialog._positionAnchored(el.getBoundingClientRect());
|
|
||||||
});
|
|
||||||
ro.observe(el);
|
|
||||||
}
|
|
||||||
anchorError = null;
|
anchorError = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Anchor selector missed — don't snap to default, just keep current
|
// Anchor selector missed — don't snap to default, just keep current
|
||||||
// position and show a note.
|
// position and show a note.
|
||||||
anchorError = "Couldn't find the training form on this page.";
|
anchorError = "Couldn't find the training UI on this page.";
|
||||||
render();
|
render();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user