New fix a lot problem

This commit is contained in:
Longtail committed 2026-10-31 22:33:54 +08:00
1 parent ad7a9260b4
commit 778384b83d
2 files changed
+4 -22

No files matched your search

+3 -22
View File
@@ -9,7 +9,6 @@
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
const visible = el => !!el && !!el.getClientRects().length && getComputedStyle(el).visibility !== 'hidden'; const visible = el => !!el && !!el.getClientRects().length && getComputedStyle(el).visibility !== 'hidden';
let flow = null, busy = false, running = false, panel, message, nextButton, resumeButton, retryButton, stopButton; let flow = null, busy = false, running = false, panel, message, nextButton, resumeButton, retryButton, stopButton;
let automationStopped = false, automationReady = false;
let actions, toolbar, panelToggle, hideButton, restoreButton, panelHidden = false, visibilitySaving = false; let actions, toolbar, panelToggle, hideButton, restoreButton, panelHidden = false, visibilitySaving = false;
class Stopped extends Error {} class Stopped extends Error {}
@@ -22,9 +21,9 @@
} }
async function call(route, body = {}) { async function call(route, body = {}) {
const run = flow?.id; const run = flow?.id;
if (automationStopped || !run || flow.paused) throw new Stopped(); if (!run || flow.paused) throw new Stopped();
const data = await request(route, { ...body, run }); const data = await request(route, { ...body, run });
if (automationStopped || flow?.id !== run || flow.paused) throw new Stopped(); if (flow?.id !== run || flow.paused) throw new Stopped();
return data; return data;
} }
async function save(patch) { async function save(patch) {
@@ -32,15 +31,13 @@
flow = data.flow; flow = data.flow;
} }
const phase = name => save({ phase: name }); const phase = name => save({ phase: name });
function check(run) { if (automationStopped || flow?.id !== run || flow.paused) throw new Stopped(); } function check(run) { if (flow?.id !== run || flow.paused) throw new Stopped(); }
function show(text, error = false) { function show(text, error = false) {
message.textContent = text; message.textContent = text;
panel.style.borderColor = error ? '#d86d20' : '#d3d9e2'; panel.style.borderColor = error ? '#d86d20' : '#d3d9e2';
controls(); controls();
} }
function controls() { function controls() {
const host = document.getElementById('dww11-extension-panel');
if (host) host.setAttribute('data-auto-news-state', JSON.stringify({version: 1, ready: automationReady, idle: automationReady && !flow && !busy && !running, paused: !!flow?.paused, phase: flow?.phase || null}));
if (!nextButton) return; if (!nextButton) return;
nextButton.disabled = busy || !!flow; nextButton.disabled = busy || !!flow;
resumeButton.hidden = !flow || (!flow.paused && running); resumeButton.hidden = !flow || (!flow.paused && running);
@@ -167,15 +164,12 @@
el.dispatchEvent(new Event('change', { bubbles: true })); el.dispatchEvent(new Event('change', { bubbles: true }));
} }
async function begin() { async function begin() {
automationStopped = false;
if (location.hostname === 'dww11.com') { location.assign(HOME); return; } if (location.hostname === 'dww11.com') { location.assign(HOME); return; }
await recordRestriction(); await recordRestriction();
if (automationStopped) return;
flow = (await request('/start')).flow; flow = (await request('/start')).flow;
await drive(); await drive();
} }
async function resume(retry = false) { async function resume(retry = false) {
automationStopped = false;
if (location.hostname === 'dww11.com') { location.assign(HOME); return; } if (location.hostname === 'dww11.com') { location.assign(HOME); return; }
if (retry && !confirm('将重新提交本次抽到的账号(不抽新账号)。如上次提交已成功,可能再次登录。确认重试?')) return; if (retry && !confirm('将重新提交本次抽到的账号(不抽新账号)。如上次提交已成功,可能再次登录。确认重试?')) return;
flow = (await request('/resume')).flow; flow = (await request('/resume')).flow;
@@ -188,7 +182,6 @@
} }
async function drive() { async function drive() {
if (automationStopped && flow && !flow.paused) { await suspend('新闻工作台已终止流程。'); return; }
if (running || !flow || flow.paused) return; if (running || !flow || flow.paused) return;
running = true; controls(); running = true; controls();
const run = flow.id; const run = flow.id;
@@ -333,7 +326,6 @@
async function init() { async function init() {
mount(); mount();
const info = await request('/hello'); const info = await request('/hello');
automationReady = true;
panelVisibility(info.panelHidden); panelVisibility(info.panelHidden);
flow = info.flow; flow = info.flow;
if (flow && !info.owned) { if (flow && !info.owned) {
@@ -346,16 +338,5 @@
await recordRestriction(); await recordRestriction();
} }
} }
// Public bridge exposes no credentials and only permits stopping, never starting login.
document.addEventListener('dww11:auto-stop', () => {
automationStopped = true;
const current = flow;
if (!current || current.paused) return;
current.paused = true; // Synchronously invalidate in-flight continuations.
controls();
request('/suspend', {run: current.id, reason: '新闻工作台已终止流程。'})
.then(() => show('新闻工作台已终止流程;如需恢复,请手动继续。', true))
.catch(error => show(error.message, true));
});
init().catch(e => { if (message) { panelVisibility(false); show('扩展启动失败:' + e.message, true); } }); init().catch(e => { if (message) { panelVisibility(false); show('扩展启动失败:' + e.message, true); } });
})(); })();
+1
View File
@@ -164,3 +164,4 @@ export async function operate(route, body = {}, sender = {}) {
return { ok: true }; return { ok: true };
}); });
} }