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

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

+11 -10
View File
@@ -1,7 +1,7 @@
// ==UserScript==
// @name 新闻工作台 · 导入排版与流程
// @namespace local.dww11.auto-news
// @version 0.2.1
// @version 0.2.2
// @match https://www.dww11.com/*
// @match https://dww11.com/*
// @match https://house.dww11.com/*
@@ -439,7 +439,7 @@
if (switcher) switcher.checked = Number(win.wysiwyg) === 0;
}
async function importPrepared(options = {}) {
const { signal, automatic = false } = options;
const { signal, automatic = false, verifyImages = true } = options;
signal?.throwIfAborted();
if (busy) throw new Error('正在导入,请勿重复点击。');
if (!article) throw new Error('请先选择文章目录或文章包。');
@@ -492,10 +492,10 @@
signal?.throwIfAborted();
setEditor(selected.title, bbcode);
const raw = win.getEditorContents();
if (Number(win.wysiwyg) === 1) {
if (Number(win.wysiwyg) === 1 && verifyImages) {
const expected = Array.from(bbcode.matchAll(/\[attachimg\](\d+)\[\/attachimg\]/g), match => match[1]);
await verifyEditorImages(doc.querySelector('#e_iframe')?.contentDocument?.body || win.editdoc?.body, expected, signal);
} else if (raw !== bbcode) throw new Error('正文填写校验失败。');
} else if (Number(win.wysiwyg) !== 1 && raw !== bbcode) throw new Error('正文填写校验失败。');
if (doc.querySelector('#subject').value !== selected.title) throw new Error('标题填写校验失败。');
committed = true;
} catch (error) {
@@ -727,7 +727,7 @@ const cleanText = value => String(value || '').replace(/\s+/g, ' ').trim();
}
window.DWW11Formatter = Object.freeze({
format(expectedSource) {
format(expectedSource, {verifyImages = true} = {}) {
if (Number(window.wysiwyg) !== 1) throw new Error('请切换到可视化编辑器后排版');
const body = document.querySelector('#e_iframe')?.contentDocument?.body;
if (!body) throw new Error('编辑器未就绪');
@@ -740,7 +740,7 @@ window.DWW11Formatter = Object.freeze({
footer.remove();
formatBody(body, expectedSource, expected);
const after = [...body.querySelectorAll('img')].map(x => [x.id, x.getAttribute('aid'), x.getAttribute('src')].join(':'));
if (JSON.stringify(images) !== JSON.stringify(after)) throw new Error('排版后图片标识或顺序改变');
if (verifyImages && JSON.stringify(images) !== JSON.stringify(after)) throw new Error('排版后图片标识或顺序改变');
if (body.querySelectorAll('[data-dww11-wx-source="1"]').length !== 1) throw new Error('来源尾注数量异常');
body.dispatchEvent(new Event('input', {bubbles:true}));
return {images: after, source: expected};
@@ -892,14 +892,15 @@ window.DWW11Formatter = Object.freeze({
const prepared=await window.DWW11Importer.stagePackage(pack);assertLive(epoch);
if(prepared.warnings?.length)throw new Error('文章需要人工处理:'+prepared.warnings.join(';'));
await event('importing');assertLive(epoch);status('上传图片并填写文章…');
const result=await window.DWW11Importer.importPrepared({automatic:true,signal:aborter.signal});assertLive(epoch);
const result=await window.DWW11Importer.importPrepared({automatic:true,verifyImages:false,signal:aborter.signal});assertLive(epoch);
if(result?.cancelled)throw new Error('导入已取消');
await event('formatting');assertLive(epoch);
window.DWW11Formatter.format(job.source);assertLive(epoch);
window.DWW11Formatter.format(job.source,{verifyImages:false});assertLive(epoch);
const snapshot=editorSnapshot();
if(snapshot.title!==job.title)throw new Error('标题校验失败');
await window.DWW11Importer.verifyEditorImages(
document.querySelector('#e_iframe').contentDocument.body, result.attachmentOrder, aborter.signal);
// 按用户要求暂停图片检查;保留原调用以便恢复。
// await window.DWW11Importer.verifyEditorImages(
// document.querySelector('#e_iframe').contentDocument.body, result.attachmentOrder, aborter.signal);
assertLive(epoch);
await event('awaiting_user_review',{snapshot});assertLive(epoch);
active={...job,state:'awaiting_user_review'};saveLocal({id:job.id});
+2 -2
View File
@@ -172,7 +172,7 @@ const cleanText = value => String(value || '').replace(/\s+/g, ' ').trim();
}
window.DWW11Formatter = Object.freeze({
format(expectedSource) {
format(expectedSource, {verifyImages = true} = {}) {
if (Number(window.wysiwyg) !== 1) throw new Error('请切换到可视化编辑器后排版');
const body = document.querySelector('#e_iframe')?.contentDocument?.body;
if (!body) throw new Error('编辑器未就绪');
@@ -185,7 +185,7 @@ window.DWW11Formatter = Object.freeze({
footer.remove();
formatBody(body, expectedSource, expected);
const after = [...body.querySelectorAll('img')].map(x => [x.id, x.getAttribute('aid'), x.getAttribute('src')].join(':'));
if (JSON.stringify(images) !== JSON.stringify(after)) throw new Error('排版后图片标识或顺序改变');
if (verifyImages && JSON.stringify(images) !== JSON.stringify(after)) throw new Error('排版后图片标识或顺序改变');
if (body.querySelectorAll('[data-dww11-wx-source="1"]').length !== 1) throw new Error('来源尾注数量异常');
body.dispatchEvent(new Event('input', {bubbles:true}));
return {images: after, source: expected};
+3 -3
View File
@@ -439,7 +439,7 @@
if (switcher) switcher.checked = Number(win.wysiwyg) === 0;
}
async function importPrepared(options = {}) {
const { signal, automatic = false } = options;
const { signal, automatic = false, verifyImages = true } = options;
signal?.throwIfAborted();
if (busy) throw new Error('正在导入,请勿重复点击。');
if (!article) throw new Error('请先选择文章目录或文章包。');
@@ -492,10 +492,10 @@
signal?.throwIfAborted();
setEditor(selected.title, bbcode);
const raw = win.getEditorContents();
if (Number(win.wysiwyg) === 1) {
if (Number(win.wysiwyg) === 1 && verifyImages) {
const expected = Array.from(bbcode.matchAll(/\[attachimg\](\d+)\[\/attachimg\]/g), match => match[1]);
await verifyEditorImages(doc.querySelector('#e_iframe')?.contentDocument?.body || win.editdoc?.body, expected, signal);
} else if (raw !== bbcode) throw new Error('正文填写校验失败。');
} else if (Number(win.wysiwyg) !== 1 && raw !== bbcode) throw new Error('正文填写校验失败。');
if (doc.querySelector('#subject').value !== selected.title) throw new Error('标题填写校验失败。');
committed = true;
} catch (error) {
+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'));
+5 -4
View File
@@ -80,14 +80,15 @@
const prepared=await window.DWW11Importer.stagePackage(pack);assertLive(epoch);
if(prepared.warnings?.length)throw new Error('文章需要人工处理:'+prepared.warnings.join(';'));
await event('importing');assertLive(epoch);status('上传图片并填写文章…');
const result=await window.DWW11Importer.importPrepared({automatic:true,signal:aborter.signal});assertLive(epoch);
const result=await window.DWW11Importer.importPrepared({automatic:true,verifyImages:false,signal:aborter.signal});assertLive(epoch);
if(result?.cancelled)throw new Error('导入已取消');
await event('formatting');assertLive(epoch);
window.DWW11Formatter.format(job.source);assertLive(epoch);
window.DWW11Formatter.format(job.source,{verifyImages:false});assertLive(epoch);
const snapshot=editorSnapshot();
if(snapshot.title!==job.title)throw new Error('标题校验失败');
await window.DWW11Importer.verifyEditorImages(
document.querySelector('#e_iframe').contentDocument.body, result.attachmentOrder, aborter.signal);
// 按用户要求暂停图片检查;保留原调用以便恢复。
// await window.DWW11Importer.verifyEditorImages(
// document.querySelector('#e_iframe').contentDocument.body, result.attachmentOrder, aborter.signal);
assertLive(epoch);
await event('awaiting_user_review',{snapshot});assertLive(epoch);
active={...job,state:'awaiting_user_review'};saveLocal({id:job.id});