Compare commits
3 Commits
578736a492
...
76e3ba2488
| Author | SHA1 | Date | |
|---|---|---|---|
| 76e3ba2488 | |||
| b03cc80665 | |||
| 501c6746eb |
+20
-5
@@ -35,12 +35,29 @@ function findAnchorElement() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function start() {
|
function start() {
|
||||||
|
try {
|
||||||
const store = new Store({
|
const store = new Store({
|
||||||
storage: localStorage,
|
storage: localStorage,
|
||||||
onWarn: (m) => console.warn(m),
|
onWarn: (m) => console.warn(m),
|
||||||
});
|
});
|
||||||
const prefs = store.getPrefs();
|
const prefs = store.getPrefs();
|
||||||
|
|
||||||
|
// State that applyMode() and render() may touch on first call.
|
||||||
|
// Declared up-front to avoid TDZ ReferenceError if applyMode()'s
|
||||||
|
// anchor-miss branch fires before the natural declaration point.
|
||||||
|
let lastSnapshot = null;
|
||||||
|
let lastAttr = null;
|
||||||
|
let lastDelta = 0;
|
||||||
|
let anchorError = null;
|
||||||
|
|
||||||
|
// One-time migration: dialog now defaults to bottom-left, so reset any
|
||||||
|
// previously-saved position from the bottom-right era.
|
||||||
|
if (prefs.pos && (prefs.pos.x !== 0 || prefs.pos.y !== 0)) {
|
||||||
|
console.info('[tat] resetting dialog position to new bottom-left default');
|
||||||
|
prefs.pos = { x: 0, y: 0 };
|
||||||
|
store.setPos(prefs.pos);
|
||||||
|
}
|
||||||
|
|
||||||
const dialog = new Dialog({
|
const dialog = new Dialog({
|
||||||
onTargetChange: (v) => {
|
onTargetChange: (v) => {
|
||||||
const attr = currentAttribute()?.attr;
|
const attr = currentAttribute()?.attr;
|
||||||
@@ -60,11 +77,6 @@ function start() {
|
|||||||
dialog.mount({ initialMode: prefs.mode, initialPos: prefs.pos });
|
dialog.mount({ initialMode: prefs.mode, initialPos: prefs.pos });
|
||||||
applyMode();
|
applyMode();
|
||||||
|
|
||||||
let lastSnapshot = null;
|
|
||||||
let lastAttr = null;
|
|
||||||
let lastDelta = 0;
|
|
||||||
let anchorError = null;
|
|
||||||
|
|
||||||
function snapshot() {
|
function snapshot() {
|
||||||
const a = currentAttribute();
|
const a = currentAttribute();
|
||||||
if (!a) {
|
if (!a) {
|
||||||
@@ -142,6 +154,9 @@ function start() {
|
|||||||
},
|
},
|
||||||
onParseFail: (url) => console.warn('[tat] could not parse train response from', url),
|
onParseFail: (url) => console.warn('[tat] could not parse train response from', url),
|
||||||
});
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error('[tat] failed to start:', e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (location.hash === '#tat-test') {
|
if (location.hash === '#tat-test') {
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ export class Dialog {
|
|||||||
|
|
||||||
if (initialMode === 'free') {
|
if (initialMode === 'free') {
|
||||||
root.style.bottom = '20px';
|
root.style.bottom = '20px';
|
||||||
root.style.right = '20px';
|
root.style.left = '20px';
|
||||||
if (initialPos.x || initialPos.y) {
|
if (initialPos.x || initialPos.y) {
|
||||||
root.style.transform = `translate(${initialPos.x}px, ${initialPos.y}px)`;
|
root.style.transform = `translate(${initialPos.x}px, ${initialPos.y}px)`;
|
||||||
}
|
}
|
||||||
@@ -124,7 +124,7 @@ export class Dialog {
|
|||||||
this.root.style.right = '';
|
this.root.style.right = '';
|
||||||
if (mode === 'free') {
|
if (mode === 'free') {
|
||||||
this.root.style.bottom = '20px';
|
this.root.style.bottom = '20px';
|
||||||
this.root.style.right = '20px';
|
this.root.style.left = '20px';
|
||||||
} else if (anchorInfo && anchorInfo.canAnchor) {
|
} else if (anchorInfo && anchorInfo.canAnchor) {
|
||||||
this._positionAnchored(anchorInfo.rect);
|
this._positionAnchored(anchorInfo.rect);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -315,7 +315,7 @@
|
|||||||
this.mode = opts.initialMode || 'free';
|
this.mode = opts.initialMode || 'free';
|
||||||
if (this.mode === 'free') {
|
if (this.mode === 'free') {
|
||||||
root.style.bottom = '20px';
|
root.style.bottom = '20px';
|
||||||
root.style.right = '20px';
|
root.style.left = '20px';
|
||||||
if (opts.initialPos && (opts.initialPos.x || opts.initialPos.y)) {
|
if (opts.initialPos && (opts.initialPos.x || opts.initialPos.y)) {
|
||||||
root.style.transform = 'translate(' + opts.initialPos.x + 'px, ' + opts.initialPos.y + 'px)';
|
root.style.transform = 'translate(' + opts.initialPos.x + 'px, ' + opts.initialPos.y + 'px)';
|
||||||
}
|
}
|
||||||
@@ -327,7 +327,7 @@
|
|||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
if (!this.root) return;
|
if (!this.root) return;
|
||||||
this.root.style.transform = ''; this.root.style.top = ''; this.root.style.bottom = ''; this.root.style.left = ''; this.root.style.right = '';
|
this.root.style.transform = ''; this.root.style.top = ''; this.root.style.bottom = ''; this.root.style.left = ''; this.root.style.right = '';
|
||||||
if (mode === 'free') { this.root.style.bottom = '20px'; this.root.style.right = '20px'; }
|
if (mode === 'free') { this.root.style.bottom = '20px'; this.root.style.left = '20px'; }
|
||||||
else if (anchorInfo && anchorInfo.canAnchor) { this._positionAnchored(anchorInfo.rect); }
|
else if (anchorInfo && anchorInfo.canAnchor) { this._positionAnchored(anchorInfo.rect); }
|
||||||
else { this.root.style.top = '20px'; this.root.style.left = '50%'; this.root.style.transform = 'translateX(-50%)'; }
|
else { this.root.style.top = '20px'; this.root.style.left = '50%'; this.root.style.transform = 'translateX(-50%)'; }
|
||||||
}
|
}
|
||||||
@@ -446,9 +446,26 @@
|
|||||||
|
|
||||||
function start() {
|
function start() {
|
||||||
if (window.__tat_started) return; window.__tat_started = true;
|
if (window.__tat_started) return; window.__tat_started = true;
|
||||||
|
try {
|
||||||
const store = new Store({ storage: localStorage, onWarn: function (m) { console.warn(m); } });
|
const store = new Store({ storage: localStorage, onWarn: function (m) { console.warn(m); } });
|
||||||
const prefs = store.getPrefs();
|
const prefs = store.getPrefs();
|
||||||
|
|
||||||
|
// State that applyMode() and render() may touch on first call.
|
||||||
|
// Declared up-front to avoid TDZ ReferenceError if applyMode()'s
|
||||||
|
// anchor-miss branch fires before the natural declaration point.
|
||||||
|
let lastSnapshot = null;
|
||||||
|
let lastAttr = null;
|
||||||
|
let lastDelta = 0;
|
||||||
|
let anchorError = null;
|
||||||
|
|
||||||
|
// One-time migration: dialog now defaults to bottom-left, so reset any
|
||||||
|
// previously-saved position from the bottom-right era.
|
||||||
|
if (prefs.pos && (prefs.pos.x !== 0 || prefs.pos.y !== 0)) {
|
||||||
|
console.info('[tat] resetting dialog position to new bottom-left default');
|
||||||
|
prefs.pos = { x: 0, y: 0 };
|
||||||
|
store.setPos(prefs.pos);
|
||||||
|
}
|
||||||
|
|
||||||
const dialog = new Dialog({
|
const dialog = new Dialog({
|
||||||
onTargetChange: function (v) {
|
onTargetChange: function (v) {
|
||||||
const a = currentAttribute(); if (!a) return; store.setTarget(a.attr, v); render();
|
const a = currentAttribute(); if (!a) return; store.setTarget(a.attr, v); render();
|
||||||
@@ -461,11 +478,6 @@
|
|||||||
dialog.mount({ initialMode: prefs.mode, initialPos: prefs.pos });
|
dialog.mount({ initialMode: prefs.mode, initialPos: prefs.pos });
|
||||||
applyMode();
|
applyMode();
|
||||||
|
|
||||||
let lastSnapshot = null;
|
|
||||||
let lastAttr = null;
|
|
||||||
let lastDelta = 0;
|
|
||||||
let anchorError = null;
|
|
||||||
|
|
||||||
function snapshot() {
|
function snapshot() {
|
||||||
const a = currentAttribute();
|
const a = currentAttribute();
|
||||||
if (!a) return { error: "Couldn't read attribute — Torn may have updated the page." };
|
if (!a) return { error: "Couldn't read attribute — Torn may have updated the page." };
|
||||||
@@ -527,6 +539,9 @@
|
|||||||
onTrain: function (e) { store.recordTrain(e.attr, e.delta, e.ts); lastDelta = e.delta; render(); },
|
onTrain: function (e) { store.recordTrain(e.attr, e.delta, e.ts); lastDelta = e.delta; render(); },
|
||||||
onParseFail: function (url) { console.warn('[tat] could not parse train response from', url); },
|
onParseFail: function (url) { console.warn('[tat] could not parse train response from', url); },
|
||||||
});
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error('[tat] failed to start:', e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== self-test (only when location.hash === '#tat-test') =====
|
// ===== self-test (only when location.hash === '#tat-test') =====
|
||||||
|
|||||||
Reference in New Issue
Block a user