修复新闻工作台换号联动流程

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
LongtailandCopilot committed 2026-11-01 15:11:41 +08:00
1 parent 7ab0bc3485
commit fd9474d0e1
15 files changed
+203 -34

No files matched your search

+30 -3
View File
@@ -1,7 +1,7 @@
// ==UserScript==
// @name 新闻工作台 · 本地连接
// @namespace local.dww11.auto-news
// @version 0.1.1
// @version 0.1.2
// @match https://www.dww11.com/*
// @match https://dww11.com/*
// @match https://house.dww11.com/*
@@ -15,7 +15,7 @@
// ==/UserScript==
(() => {
'use strict';
const allowed = new Set(['heartbeat','next','package','event','accept','switch-begin','takeover','stop','current','skip']);
const allowed = new Set(['heartbeat','next','package','event','accept','switch-begin','takeover','start','pause','stop','current','skip']);
let token = GM_getValue('pairToken',''), port = GM_getValue('pairPort',8770);
let stopRevision = 0;
const signalStop = () => { stopRevision++; document.dispatchEvent(new CustomEvent('dww11:auto-stop')); };
@@ -35,13 +35,14 @@
try {message=JSON.parse(event.detail);} catch {return;}
if (!allowed.has(message.route) || typeof message.id !== 'string') return;
try {
if (message.route==='stop') { GM_setValue('halted',true); signalStop(); }
if (message.route==='stop'||message.route==='pause') { GM_setValue('halted',true); signalStop(); }
const revision = stopRevision;
let value=await request(message.route,message.body || {});
if (message.route==='heartbeat') {
if (revision !== stopRevision) value = {...value, running:false, reason:'终止后忽略旧连接响应'};
GM_setValue('halted',!value.running);
if (!value.running) signalStop();
document.dispatchEvent(new CustomEvent('dww11:run-state',{detail:Boolean(value.running)}));
}
document.dispatchEvent(new CustomEvent('dww11:local-response',{detail:JSON.stringify({id:message.id,value})}));
} catch(error) {
@@ -56,6 +57,32 @@
const shadow=host.attachShadow({mode:'closed'});
shadow.innerHTML='<style>section{font:13px/1.6 system-ui;background:white;color:#24364a;border:1px solid #ccd7e0;border-radius:10px;padding:12px;width:250px;box-shadow:0 3px 20px #0002}button,input{font:inherit;box-sizing:border-box;padding:7px;margin:4px 0;width:100%}button{cursor:pointer}#halt{background:#ad302d;color:white;border:0;border-radius:6px}small{display:block}</style><section><strong>新闻工作台 · 本地连接</strong><button id="halt">终止流程</button><details><summary>连接设置</summary><label>本地端口<input id="port" type="number" min="1" max="65535"></label><label>连接码<input id="token" type="password" autocomplete="off"></label><button id="save">保存连接设置</button></details><small id="status">请启动本地工作台并配对</small></section>';
const $=id=>shadow.getElementById(id);$('port').value=port;
const start=document.createElement('button');start.id='start';start.type='button';start.textContent='开始 / 继续';
const pause=document.createElement('button');pause.id='pause';pause.type='button';pause.textContent='暂停';
$('halt').before(start);$('halt').before(pause);
let starting=false;
start.onclick=async()=>{
if(starting||start.disabled)return;
starting=true;start.disabled=true;
const revision=stopRevision;
try {
await request('start',{});
if(revision!==stopRevision) {
await request('pause',{});
$('status').textContent='已暂停;忽略较早的开始响应';
}else {
GM_setValue('halted',false);
$('status').textContent='已开始;等待执行标签继续流程';
}
}catch(error){$('status').textContent='开始失败:'+error.message;}
finally{starting=false;start.disabled=false;}
};
pause.onclick=async()=>{
GM_setValue('halted',true);signalStop();
$('status').textContent='已暂停;在途请求仍可能完成';
try {await request('pause',{});}catch(error){$('status').textContent+='。'+error.message;}
};
document.addEventListener('dww11:run-state',event=>{start.disabled=starting||Boolean(event.detail);});
const skip=document.createElement('button');skip.id='skip';skip.type='button';skip.textContent='跳过本文章';
$('halt').before(skip);
skip.onclick=()=>document.dispatchEvent(new CustomEvent('dww11:skip-article'));