Fix battle auto-detection and overlay position switching
- game-bridge.js: Replace broken Phaser.GAMES discovery (tree-shaken by Vite) with SceneManager.prototype.update monkey-patch that captures the game instance on the next frame tick - manifest.json: Run game-bridge at document_start so the patch is installed before Phaser boots - content.js: Fix position buttons only working once — was using inline style.left presence as drag check, now uses a dedicated manuallyDragged flag that only sets on actual mouse drag and resets on popup position change - Bump version to 1.1.0
This commit is contained in:
21
content.js
21
content.js
@@ -31,6 +31,7 @@
|
||||
let currentBattleState = null;
|
||||
let overlayEl = null;
|
||||
let statusText = 'Waiting for game...';
|
||||
let manuallyDragged = false;
|
||||
|
||||
// ─── Settings Management ───────────────────────────────────────────
|
||||
|
||||
@@ -49,7 +50,13 @@
|
||||
|
||||
function onSettingsChanged(changes) {
|
||||
if (changes.settings) {
|
||||
const oldPosition = settings.position;
|
||||
settings = { ...settings, ...changes.settings.newValue };
|
||||
// If position changed via storage, reset drag and force reposition
|
||||
if (settings.position !== oldPosition) {
|
||||
manuallyDragged = false;
|
||||
if (overlayEl) applyPosition(true);
|
||||
}
|
||||
updateOverlay();
|
||||
}
|
||||
}
|
||||
@@ -72,7 +79,13 @@
|
||||
settings
|
||||
});
|
||||
} else if (msg.type === 'UPDATE_SETTINGS') {
|
||||
const resetPos = msg.settings._resetPosition;
|
||||
delete msg.settings._resetPosition;
|
||||
settings = { ...settings, ...msg.settings };
|
||||
if (resetPos) {
|
||||
manuallyDragged = false;
|
||||
if (overlayEl) applyPosition(true);
|
||||
}
|
||||
updateOverlay();
|
||||
sendResponse({ ok: true });
|
||||
} else if (msg.type === 'REQUEST_REFRESH') {
|
||||
@@ -150,6 +163,7 @@
|
||||
el.style.top = (origY + dy) + 'px';
|
||||
el.style.right = 'auto';
|
||||
el.style.bottom = 'auto';
|
||||
manuallyDragged = true;
|
||||
});
|
||||
|
||||
document.addEventListener('mouseup', () => {
|
||||
@@ -183,11 +197,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
function applyPosition() {
|
||||
function applyPosition(force) {
|
||||
if (!overlayEl) return;
|
||||
// Only apply position if not manually dragged
|
||||
if (overlayEl.style.left && overlayEl.style.left !== 'auto') return;
|
||||
// Skip if user manually dragged the overlay (unless forced by popup)
|
||||
if (manuallyDragged && !force) return;
|
||||
|
||||
// Clear all position styles
|
||||
overlayEl.style.right = '';
|
||||
overlayEl.style.left = '';
|
||||
overlayEl.style.top = '';
|
||||
|
||||
Reference in New Issue
Block a user