Claude 501c6746eb fix(main): hoist let bindings to top of start() to fix TDZ on anchorError
The applyMode() function reads/writes anchorError, lastSnapshot, and other
let-bound state. Function declarations are hoisted, so applyMode() can fire
from inside the dialog.mount() / applyMode() call sequence at the top of
start() — but the let bindings themselves are not initialized until
execution reaches their declaration line, which came later.

When prefs.mode === 'anchored' and findAnchorElement() returns null, the
new 'anchor missed' branch writes to anchorError and calls render(). Both
access anchorError before its let binding is initialized, throwing
ReferenceError: Cannot access 'anchorError' before initialization.

Move all four let declarations (lastSnapshot, lastAttr, lastDelta,
anchorError) to the top of start(), before dialog.mount() and applyMode().
Function declarations are unaffected — they are hoisted regardless.
2026-06-01 22:22:29 -05:00

Torn Attribute Training Tracker

A userscript for torn.com that shows a floating dialog on the gym page with your current attribute, target, rate of gain, and an ETA to the target.

Install

  1. Install Tampermonkey (or Violentmonkey / Greasemonkey).
  2. Open torn-attribute-tracker.user.js in your editor, copy its contents.
  3. In Tampermonkey, click the dashboard → + (Create new script) → paste → save.
  4. Visit https://www.torn.com/gym.php. The dialog appears in the bottom-right.

Use

  • Type a target value in the Target field, or pick a milestone from the dropdown.
  • The dialog updates live as you train.
  • Drag the header to reposition. Click Above training UI to anchor above the gym form. Click Float free to drag again.
  • The closes the dialog for the current page session; it returns on next visit.

Targets, dialog position, and the 30-day train history are stored in localStorage.

Self-test

Load the script with #tat-test in the URL:

https://www.torn.com/gym.php#tat-test

Open the browser console; you'll see [tat] self-test results: followed by OK … / FAIL … lines.

Tests

npm install   # no deps; node:test ships with Node 18+
npm test

Files

  • torn-attribute-tracker.user.js — the script you install in Tampermonkey.
  • src/pure.js, src/store.js, src/dom.js, src/interceptor.js, src/ui.js, src/main.js — source split for testability; the user-facing file is the bundle in step 11.
  • tests/ — Node test runner (node --test).

Notes

The DOM scraper and request interceptor are best-effort matches for the current Torn gym page. If Torn updates the markup, you may need to adjust the selectors in src/dom.js and re-bundle by copying the new source into the embedded section in torn-attribute-tracker.user.js.

S
Description
No description provided
Readme 216 KiB
Languages
JavaScript 100%