diff --git a/README.md b/README.md index c06c79e..88a9388 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # 广谈大湾网 · 随机换号扩展 3.0.4 +2026-11-01:补齐新闻工作台联动接口。页面宿主 `#dww11-extension-panel` 的 `data-auto-news-state` 只公开 `ready`、`idle`、`paused` 三个状态,不包含账号或密码;监听 `dww11:auto-stop` 以暂停未完成流程,包括抽号或恢复响应尚未返回的情况。覆盖原目录后需要重新加载扩展并刷新网站,账号库和抽取记录保留。ZIP 未重新打包。 + 将提供的 `dww11-acc-switch.user.js` 重写为 Chrome / Edge Manifest V3 扩展。无需运行本机服务,无需持续授权本地文件,也无需安装 npm 依赖。 ## 安装 diff --git a/content.js b/content.js index c7f7ee1..4dce801 100644 --- a/content.js +++ b/content.js @@ -9,6 +9,7 @@ const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); 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 bridgeHost, bridgeReady = false, stopRevision = 0; let actions, toolbar, panelToggle, hideButton, restoreButton, panelHidden = false, visibilitySaving = false; class Stopped extends Error {} @@ -39,6 +40,11 @@ } function controls() { if (!nextButton) return; + // Only lifecycle flags cross into the page; never credentials or account data. + bridgeHost?.setAttribute('data-auto-news-state', JSON.stringify({ + ready: bridgeReady, idle: bridgeReady && !busy && !running && !flow, + paused: !!flow?.paused + })); nextButton.disabled = busy || !!flow; resumeButton.hidden = !flow || (!flow.paused && running); resumeButton.disabled = busy || running; @@ -107,6 +113,9 @@ async function suspend(reason) { if (flow && !flow.paused) { const run = flow.id; + flow.paused = true; + flow.reason = reason; + controls(); try { await request('/suspend', { run, reason }); } finally { if (flow?.id === run) { flow.paused = true; flow.reason = reason; } } } @@ -165,14 +174,19 @@ } async function begin() { if (location.hostname === 'dww11.com') { location.assign(HOME); return; } + const revision = stopRevision; await recordRestriction(); + if (revision !== stopRevision) return; flow = (await request('/start')).flow; + if (revision !== stopRevision) { await suspend('新闻工作台已终止流程。'); return; } await drive(); } async function resume(retry = false) { if (location.hostname === 'dww11.com') { location.assign(HOME); return; } if (retry && !confirm('将重新提交本次抽到的账号(不抽新账号)。如上次提交已成功,可能再次登录。确认重试?')) return; + const revision = stopRevision; flow = (await request('/resume')).flow; + if (revision !== stopRevision) { await suspend('新闻工作台已终止流程。'); return; } if (retry) { await save({ phase: 'logout', hops: 0, submittedAt: null, probedAt: null, invalidError: null }); location.assign(HOME); @@ -291,6 +305,7 @@ function mount() { const host = document.createElement('div'); + bridgeHost = host; host.id = 'dww11-extension-panel'; const root = host.attachShadow({ mode: 'closed' }); const style = document.createElement('style'); @@ -328,6 +343,7 @@ const info = await request('/hello'); panelVisibility(info.panelHidden); flow = info.flow; + bridgeReady = true; if (flow && !info.owned) { flow.paused = true; show('存在未完成流程。可在原标签页继续;原标签关闭后可在此接续。', true); @@ -338,5 +354,9 @@ await recordRestriction(); } } - init().catch(e => { if (message) { panelVisibility(false); show('扩展启动失败:' + e.message, true); } }); + document.addEventListener('dww11:auto-stop', () => { + stopRevision++; + if (flow && !flow.paused) void suspend('新闻工作台已终止流程。').catch(e => show(e.message, true)); + }); + init().catch(e => { bridgeReady = false; if (message) { panelVisibility(false); show('扩展启动失败:' + e.message, true); } }); })();