fix(bundle): mirror source fixes in embedded userscript
This commit is contained in:
@@ -123,12 +123,6 @@
|
|||||||
|
|
||||||
// ===== dom.js (embedded) =====
|
// ===== dom.js (embedded) =====
|
||||||
const TAT_KNOWN_ATTRS = ['strength', 'defense', 'speed', 'dexterity', 'endurance', 'intelligence'];
|
const TAT_KNOWN_ATTRS = ['strength', 'defense', 'speed', 'dexterity', 'endurance', 'intelligence'];
|
||||||
const TAT_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",
|
|
||||||
];
|
|
||||||
function currentAttribute() {
|
function currentAttribute() {
|
||||||
const li = tatFindActiveAttributeLi();
|
const li = tatFindActiveAttributeLi();
|
||||||
if (!li) return null;
|
if (!li) return null;
|
||||||
@@ -180,16 +174,15 @@
|
|||||||
return tatParseNumber(valueSpan.textContent);
|
return tatParseNumber(valueSpan.textContent);
|
||||||
}
|
}
|
||||||
function tatFindGymName() {
|
function tatFindGymName() {
|
||||||
// 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 TAT_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.indexOf(name + '.') === 0 || label.indexOf(name + ' ') === 0) {
|
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;
|
||||||
}
|
}
|
||||||
@@ -445,9 +438,14 @@
|
|||||||
|
|
||||||
// ===== main.js (embedded) =====
|
// ===== main.js (embedded) =====
|
||||||
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"]',
|
||||||
@@ -459,18 +457,7 @@
|
|||||||
];
|
];
|
||||||
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