Three changes that ride together because they touch the same surface. A control link to the master. lib/master-link.ts dials out to <master>/ws/instance and holds it open, so the dashboard can trigger a trade or queue an AutoBuyer run here. Commands call the same functions the local pages call — runTrade, startScheduler, queueRun — so nothing reaches the broker by a path the UI does not also use. Reports prefer the socket and fall back to the existing POST, which keeps older masters working unchanged. startMasterLink is idempotent, and that matters more than it looks: getClients() is lazy and starts the link, so the first command re-enters it from inside a command the live socket is waiting to ack. Tearing the socket down there loses the ack and reports a trade that actually executed as a failure — which invites pressing the button twice. queueRun is lifted out of the automations route so the socket and HTTP share one copy of the input clamping that decides how many times a purchase fires. Page capture loses its switch and gains a scope. It now runs every tick, but only against the active tab of the last-focused window that matches host_permissions — so it follows the page in front of you and stops when you switch away, where before it would fall back to any firm tab left open in the background. autobuyer_enabled is gone entirely. The AutoBuyer is ready whenever the runner is; a run happens because someone asked for one. That does mean a queued run executes as soon as clicker/runner.py claims it, with no second gate — stopping the runner is now the way to make a machine idle. Extension to 0.10.0; it needs a manual reload at chrome://extensions. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
55 lines
2.0 KiB
JavaScript
55 lines
2.0 KiB
JavaScript
const FIELDS = ['apiBase', 'pollSeconds', 'elementSelector'];
|
|
const DEFAULTS = {
|
|
apiBase: 'http://localhost:3000',
|
|
pollSeconds: 3,
|
|
elementSelector: '',
|
|
};
|
|
|
|
async function load() {
|
|
const cfg = { ...DEFAULTS, ...(await chrome.storage.local.get(FIELDS)) };
|
|
for (const f of FIELDS) document.getElementById(f).value = cfg[f];
|
|
render();
|
|
}
|
|
|
|
async function render() {
|
|
const { state = {} } = await chrome.storage.local.get('state');
|
|
|
|
// There is nothing to switch on: either it can reach the dashboard or it
|
|
// cannot. `waiting` below says why a tick captured nothing.
|
|
const color = state.connected ? '#22c55e' : '#ef4444';
|
|
const label = state.connected ? 'Capturing' : 'Disconnected';
|
|
|
|
const cap = state.lastCapture;
|
|
const detail = state.waiting
|
|
? `<div class="muted">${esc(state.waiting)}</div>`
|
|
: cap
|
|
? `<div class="muted">${esc(cap.title || cap.url)}<br>${(cap.bytes / 1024).toFixed(1)} KB · ${new Date(cap.at).toLocaleTimeString()}</div>`
|
|
: '';
|
|
|
|
document.getElementById('status').innerHTML =
|
|
`<span class="dot" style="background:${color}"></span><strong>${label}</strong>` +
|
|
detail +
|
|
(state.error ? `<div class="err">${esc(state.error)}</div>` : '');
|
|
}
|
|
|
|
document.getElementById('save').addEventListener('click', async () => {
|
|
const patch = {};
|
|
for (const f of FIELDS) patch[f] = document.getElementById(f).value.trim();
|
|
patch.pollSeconds = Number(patch.pollSeconds) || DEFAULTS.pollSeconds;
|
|
patch.apiBase = patch.apiBase || DEFAULTS.apiBase;
|
|
await chrome.storage.local.set(patch);
|
|
setTimeout(render, 400);
|
|
});
|
|
|
|
document.getElementById('now').addEventListener('click', () => {
|
|
chrome.runtime.sendMessage({ type: 'capture-now' }, () => setTimeout(render, 200));
|
|
});
|
|
|
|
chrome.storage.onChanged.addListener((c, area) => { if (area === 'local' && 'state' in c) render(); });
|
|
|
|
function esc(s) {
|
|
return String(s).replace(/[&<>"]/g, (ch) => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[ch]));
|
|
}
|
|
|
|
load();
|