transproof-dsh-plugin 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +21 -2
- package/app/config.js +157 -0
- package/app/index.html +1843 -0
- package/app/js/01-core.js +247 -0
- package/app/js/02-prompts-reverse.js +504 -0
- package/app/js/03-translate.js +429 -0
- package/app/js/04-settings-data.js +410 -0
- package/app/js/05-files-docx.js +842 -0
- package/app/js/06-track-scan.js +652 -0
- package/app/js/07-run-features.js +701 -0
- package/app/js/08-render-audit.js +2050 -0
- package/app/js/09-gloss.js +774 -0
- package/app/js/10-app-init.js +220 -0
- package/app/js/11-feedback.js +199 -0
- package/app/js/12-editbox.js +75 -0
- package/app/js/13-pipeline.js +206 -0
- package/app/js/14-noun-verify.js +251 -0
- package/app/js/15-delivery-report.js +151 -0
- package/app/js/16-wiki-verify.js +115 -0
- package/client.js +69 -0
- package/cordis.patch.yml +9 -0
- package/host/index.js +189 -0
- package/icon.svg +32 -0
- package/locale/en.json +1 -0
- package/locale/zh.json +1 -0
- package/package.json +32 -4
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/* ═══════════ 项目进度看板(v4.5 协作)═══════════ */
|
|
2
|
+
const LS_PROJ = 'tp.project';
|
|
3
|
+
let PROJECT = load(LS_PROJ, { name:'', currentId:null, tasks:[] });
|
|
4
|
+
const TASK_STATUS = [
|
|
5
|
+
{ key:'todo', label:'未开始', cls:'todo' },
|
|
6
|
+
{ key:'translating', label:'翻译中', cls:'warn' },
|
|
7
|
+
{ key:'proofreading', label:'校对中', cls:'pp' },
|
|
8
|
+
{ key:'done', label:'已完成', cls:'ok' },
|
|
9
|
+
];
|
|
10
|
+
function saveProject(){ save(LS_PROJ, PROJECT); }
|
|
11
|
+
function renderProject(){
|
|
12
|
+
const total = PROJECT.tasks.length;
|
|
13
|
+
const done = PROJECT.tasks.filter(t => t.status === 'done').length;
|
|
14
|
+
const translating = PROJECT.tasks.filter(t => t.status === 'translating').length;
|
|
15
|
+
const proofreading = PROJECT.tasks.filter(t => t.status === 'proofreading').length;
|
|
16
|
+
const todo = total - done - translating - proofreading;
|
|
17
|
+
const pct = total ? Math.round(done / total * 100) : 0;
|
|
18
|
+
$('#proj-name').value = PROJECT.name || '';
|
|
19
|
+
$('#proj-count').textContent = total + ' 个任务';
|
|
20
|
+
$('#proj-stat').innerHTML =
|
|
21
|
+
'<span>总任务 <b style="color:var(--tx)">' + total + '</b></span>' +
|
|
22
|
+
'<span style="color:var(--ok)">已完成 ' + done + '</span>' +
|
|
23
|
+
'<span style="color:var(--warn)">翻译中 ' + translating + '</span>' +
|
|
24
|
+
'<span style="color:var(--pp)">校对中 ' + proofreading + '</span>' +
|
|
25
|
+
'<span style="color:var(--tx3)">未开始 ' + todo + '</span>';
|
|
26
|
+
$('#proj-bar').style.width = pct + '%';
|
|
27
|
+
$('#proj-bar-txt').textContent = total ? ('总进度 ' + pct + '%(' + done + '/' + total + ')') : '还没有任务,先在上方添加一个吧';
|
|
28
|
+
const rows = PROJECT.tasks.map((t, i) => {
|
|
29
|
+
const statusBtns = TASK_STATUS.map(s =>
|
|
30
|
+
'<button class="mini-status' + (t.status === s.key ? ' on ' + s.cls : '') + '" data-i="' + i + '" data-s="' + s.key + '">' + s.label + '</button>'
|
|
31
|
+
).join('');
|
|
32
|
+
const proofBadge = t.proof ? (() => {
|
|
33
|
+
const p = t.proof;
|
|
34
|
+
const stageLabel = { full:'完整', pass1:'一校✓', pass2:'二校✓' }[p.stage] || '';
|
|
35
|
+
const errKeys = Object.keys(p.errors || {});
|
|
36
|
+
const errTxt = errKeys.slice(0, 3).map(k => k + (p.errors[k] || 0)).join(' ');
|
|
37
|
+
const bad = ((p.termAudit || {}).conflict || 0) + ((p.termAudit || {}).multi || 0);
|
|
38
|
+
let h = '';
|
|
39
|
+
if(stageLabel) h += '<span class="proof-badge info">' + esc(stageLabel) + '</span>';
|
|
40
|
+
if(errTxt) h += '<span class="proof-badge info">' + esc(errTxt) + '</span>';
|
|
41
|
+
if(bad > 0) h += '<span class="proof-badge warn">⚠术语' + bad + '</span>';
|
|
42
|
+
return h;
|
|
43
|
+
})() : '';
|
|
44
|
+
const isCur = t.id === PROJECT.currentId;
|
|
45
|
+
return '<div class="' + (isCur ? 'cur-task' : '') + '" style="display:flex;gap:8px;align-items:center;padding:8px 12px;background:var(--bg2);border:1px solid var(--bd);border-radius:8px;flex-wrap:wrap">' +
|
|
46
|
+
'<div style="flex:1;min-width:160px"><b style="font-size:13px">' + esc(t.name) + '</b>' +
|
|
47
|
+
(t.owner ? '<span style="color:var(--tx3);font-size:11px;margin-left:8px">👤 ' + esc(t.owner) + '</span>' : '') +
|
|
48
|
+
(isCur ? '<span style="color:var(--ac);font-size:11px;margin-left:8px">◎ 当前</span>' : '') +
|
|
49
|
+
(proofBadge ? '<span style="display:inline-flex;gap:4px;flex-wrap:wrap;margin-left:8px;vertical-align:middle">' + proofBadge + '</span>' : '') +
|
|
50
|
+
'</div>' +
|
|
51
|
+
'<div style="display:flex;gap:4px;flex-wrap:wrap">' + statusBtns + '</div>' +
|
|
52
|
+
'<button class="btn x" data-cur="' + i + '" title="设为当前任务:校对结果自动同步到此任务">◎</button>' +
|
|
53
|
+
'<button class="btn x" data-del="' + i + '" title="删除任务">✕</button>' +
|
|
54
|
+
'</div>';
|
|
55
|
+
}).join('');
|
|
56
|
+
$('#proj-list').innerHTML = rows || '<div class="empty">还没有任务。在上方输入任务名,点「+ 添加任务」开始。</div>';
|
|
57
|
+
document.querySelectorAll('#proj-list .mini-status').forEach(b => {
|
|
58
|
+
b.onclick = () => { PROJECT.tasks[+b.dataset.i].status = b.dataset.s; PROJECT.tasks[+b.dataset.i].updatedAt = Date.now(); saveProject(); renderProject(); };
|
|
59
|
+
});
|
|
60
|
+
document.querySelectorAll('#proj-list [data-cur]').forEach(b => {
|
|
61
|
+
b.onclick = () => { PROJECT.currentId = PROJECT.tasks[+b.dataset.cur].id; saveProject(); renderProject(); toast('已设为当前任务,校对结果将自动同步到此任务'); };
|
|
62
|
+
});
|
|
63
|
+
document.querySelectorAll('#proj-list [data-del]').forEach(b => {
|
|
64
|
+
b.onclick = () => { const t = PROJECT.tasks.splice(+b.dataset.del, 1)[0]; if(t && t.id === PROJECT.currentId) PROJECT.currentId = null; saveProject(); renderProject(); };
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
$('#proj-rename').onclick = () => { PROJECT.name = $('#proj-name').value.trim(); saveProject(); toast('项目已命名'); };
|
|
68
|
+
$('#task-add').onclick = () => {
|
|
69
|
+
const name = $('#task-name').value.trim();
|
|
70
|
+
if(!name){ toast('请输入任务名', 'w'); return; }
|
|
71
|
+
PROJECT.tasks.push({ id: 't' + Date.now() + Math.random().toString(36).slice(2,6), name, owner: $('#task-owner').value.trim(), status: 'todo', updatedAt: Date.now() });
|
|
72
|
+
$('#task-name').value = ''; $('#task-owner').value = '';
|
|
73
|
+
saveProject(); renderProject(); toast('已添加任务:' + name);
|
|
74
|
+
};
|
|
75
|
+
$('#task-name').onkeydown = e => { if(e.key === 'Enter') $('#task-add').click(); };
|
|
76
|
+
$('#proj-export').onclick = () => {
|
|
77
|
+
if(!PROJECT.tasks.length){ toast('还没有任务可导出', 'w'); return; }
|
|
78
|
+
dl('项目进度_' + (PROJECT.name || today()) + '.json', JSON.stringify({ name:PROJECT.name, tasks:PROJECT.tasks, exportedAt:new Date().toISOString() }, null, 2), 'application/json');
|
|
79
|
+
};
|
|
80
|
+
$('#proj-import').onclick = () => $('#proj-file').click();
|
|
81
|
+
$('#proj-file').onchange = e => {
|
|
82
|
+
const f = e.target.files[0]; if(!f) return;
|
|
83
|
+
const rd = new FileReader();
|
|
84
|
+
rd.onload = () => {
|
|
85
|
+
try{
|
|
86
|
+
const j = JSON.parse(rd.result);
|
|
87
|
+
const tasks = Array.isArray(j) ? j : (j.tasks || []);
|
|
88
|
+
if(!tasks.length){ toast('文件里没有任务', 'w'); return; }
|
|
89
|
+
let add = 0, upd = 0;
|
|
90
|
+
tasks.forEach(t => {
|
|
91
|
+
const ex = PROJECT.tasks.find(x => x.id === t.id);
|
|
92
|
+
if(ex){ Object.assign(ex, t); upd++; }
|
|
93
|
+
else { PROJECT.tasks.push({ id: t.id || ('t'+Date.now()+Math.random().toString(36).slice(2,6)), name: t.name||'', owner: t.owner||'', status: t.status||'todo', updatedAt: t.updatedAt||Date.now(), proof: t.proof || null }); add++; }
|
|
94
|
+
});
|
|
95
|
+
if(j.name) PROJECT.name = j.name;
|
|
96
|
+
saveProject(); renderProject();
|
|
97
|
+
toast('导入完成:新增 ' + add + '、更新 ' + upd);
|
|
98
|
+
}catch(err){ toast('导入失败:' + err.message, 'e'); }
|
|
99
|
+
};
|
|
100
|
+
rd.readAsText(f);
|
|
101
|
+
e.target.value = '';
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/* ═══════════ 界面主题(明暗自适应 + 自定义主题色)═══════════ */
|
|
105
|
+
let THEME = load('tp.theme', 'auto');
|
|
106
|
+
let ACCENT = load('tp.accent', null);
|
|
107
|
+
|
|
108
|
+
function shadeHex(hex, pct){
|
|
109
|
+
const n = parseInt(hex.replace('#',''), 16);
|
|
110
|
+
let r = (n>>16)&255, g = (n>>8)&255, b = n&255;
|
|
111
|
+
const f = pct/100;
|
|
112
|
+
r = Math.round(r*(1+f)); g = Math.round(g*(1+f)); b = Math.round(b*(1+f));
|
|
113
|
+
const c = x => Math.max(0, Math.min(255, x)).toString(16).padStart(2,'0');
|
|
114
|
+
return '#' + c(r) + c(g) + c(b);
|
|
115
|
+
}
|
|
116
|
+
function applyTheme(){
|
|
117
|
+
let eff = THEME;
|
|
118
|
+
if(eff === 'auto') eff = (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) ? 'light' : 'dark';
|
|
119
|
+
document.documentElement.dataset.theme = eff;
|
|
120
|
+
}
|
|
121
|
+
function renderThemeUI(){
|
|
122
|
+
document.querySelectorAll('.theme-opt').forEach(b => b.classList.toggle('on', b.dataset.themeMode === THEME));
|
|
123
|
+
const tb = $('#themeToggle');
|
|
124
|
+
if(tb) tb.textContent = { auto:'🌓', dark:'🌙', light:'☀️' }[THEME] || '🌓';
|
|
125
|
+
}
|
|
126
|
+
function setTheme(mode){
|
|
127
|
+
THEME = mode;
|
|
128
|
+
save('tp.theme', mode);
|
|
129
|
+
applyTheme();
|
|
130
|
+
renderThemeUI();
|
|
131
|
+
}
|
|
132
|
+
function applyAccent(hex){
|
|
133
|
+
if(!/^#[0-9a-fA-F]{6}$/.test(hex)) return;
|
|
134
|
+
ACCENT = hex;
|
|
135
|
+
save('tp.accent', hex);
|
|
136
|
+
document.documentElement.style.setProperty('--ac', hex);
|
|
137
|
+
document.documentElement.style.setProperty('--ac2', shadeHex(hex, -18));
|
|
138
|
+
document.documentElement.style.setProperty('--grad-ac', 'linear-gradient(135deg,' + hex + ' 0%,' + shadeHex(hex, -28) + ' 100%)');
|
|
139
|
+
document.querySelectorAll('.accent-swatch').forEach(s => s.classList.toggle('on', s.dataset.hex.toLowerCase() === hex.toLowerCase()));
|
|
140
|
+
const pk = $('#accentPicker'); if(pk) pk.value = hex;
|
|
141
|
+
}
|
|
142
|
+
$('#themeToggle').onclick = () => {
|
|
143
|
+
const order = { auto:'dark', dark:'light', light:'auto' };
|
|
144
|
+
setTheme(order[THEME] || 'auto');
|
|
145
|
+
};
|
|
146
|
+
document.querySelectorAll('.theme-opt').forEach(b => b.onclick = () => setTheme(b.dataset.themeMode));
|
|
147
|
+
document.querySelectorAll('.accent-swatch').forEach(s => s.onclick = () => applyAccent(s.dataset.hex));
|
|
148
|
+
$('#accentPicker').onchange = e => applyAccent(e.target.value);
|
|
149
|
+
if(window.matchMedia){
|
|
150
|
+
const mq = window.matchMedia('(prefers-color-scheme: light)');
|
|
151
|
+
const onChange = () => { if(THEME === 'auto') applyTheme(); };
|
|
152
|
+
if(mq.addEventListener) mq.addEventListener('change', onChange);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/* ═══════════ 开屏动画(3 秒问候页)═══════════ */
|
|
156
|
+
const SPLASH = load('tp.splash', { on:true, slogan:'', deco:'d1' });
|
|
157
|
+
const SP_DECOS = { d1:'✦ ── ◆ ── ✧', d2:'─═══════════════─', d3:'╭─▄▀ ▊▍▍▋', d4:'〔 ❖ 〕' };
|
|
158
|
+
function spGreeting(){
|
|
159
|
+
const h = new Date().getHours();
|
|
160
|
+
return h < 5 ? '夜深了,辛苦了' : h < 11 ? '早上好' : h < 14 ? '中午好' : h < 18 ? '下午好' : '晚上好';
|
|
161
|
+
}
|
|
162
|
+
function showSplash(){
|
|
163
|
+
if(!SPLASH.on) return;
|
|
164
|
+
const el = document.createElement('div');
|
|
165
|
+
el.id = 'tp-splash';
|
|
166
|
+
el.innerHTML = '<div class="sp-box"><div class="sp-deco"></div><div class="sp-hi"></div><div class="sp-slogan"></div><div class="sp-meta">TRANSPROOF · v' + APP_VERSION + '</div></div>';
|
|
167
|
+
el.querySelector('.sp-deco').textContent = SP_DECOS[SPLASH.deco] || SP_DECOS.d1;
|
|
168
|
+
el.querySelector('.sp-hi').textContent = spGreeting() + ',欢迎回来';
|
|
169
|
+
el.querySelector('.sp-slogan').textContent = (SPLASH.slogan || '').trim() || '译校有我,落笔无忧';
|
|
170
|
+
document.body.appendChild(el);
|
|
171
|
+
setTimeout(() => { if(el.parentNode) el.parentNode.removeChild(el); }, 3300); // 2.45s 起淡出,3.3s 出 DOM
|
|
172
|
+
}
|
|
173
|
+
(function wireSplashSettings(){
|
|
174
|
+
const on = $('#splash-on'), sg = $('#splash-slogan'), dc = $('#splash-deco');
|
|
175
|
+
if(!on || !sg || !dc) return;
|
|
176
|
+
on.checked = !!SPLASH.on;
|
|
177
|
+
sg.value = SPLASH.slogan || '';
|
|
178
|
+
dc.value = SPLASH.deco || 'd1';
|
|
179
|
+
const persist = () => {
|
|
180
|
+
SPLASH.on = on.checked; SPLASH.slogan = sg.value.trim(); SPLASH.deco = dc.value;
|
|
181
|
+
save('tp.splash', SPLASH);
|
|
182
|
+
};
|
|
183
|
+
on.onchange = persist; sg.onchange = persist; dc.onchange = persist;
|
|
184
|
+
})();
|
|
185
|
+
showSplash();
|
|
186
|
+
|
|
187
|
+
/* ═══════════ 初始化 ═══════════ */
|
|
188
|
+
(function init(){
|
|
189
|
+
initTermCat();
|
|
190
|
+
fillCfg();
|
|
191
|
+
$('#prefs').value = PREFS;
|
|
192
|
+
// 版本号:接入全局常量,替换写死的 "v3.0"
|
|
193
|
+
const gv = $('#g-version'); if(gv) gv.textContent = 'v' + APP_VERSION;
|
|
194
|
+
// 主题:应用 + 渲染 + 恢复自定义主题色
|
|
195
|
+
applyTheme();
|
|
196
|
+
renderThemeUI();
|
|
197
|
+
if(ACCENT) applyAccent(ACCENT);
|
|
198
|
+
renderTerms();
|
|
199
|
+
renderDataStat();
|
|
200
|
+
updateDot();
|
|
201
|
+
// P1:渲染文件输入条
|
|
202
|
+
renderFileBar('src');
|
|
203
|
+
renderFileBar('dst');
|
|
204
|
+
// 3.0:渲染专有译词库
|
|
205
|
+
ensureRules();
|
|
206
|
+
renderGloss();
|
|
207
|
+
// 4.5:渲染项目进度看板
|
|
208
|
+
renderProject();
|
|
209
|
+
// 4.14:渲染翻译记忆
|
|
210
|
+
renderMemory();
|
|
211
|
+
if(EXT_CFG.defaults && typeof EXT_CFG.defaults === 'object'){
|
|
212
|
+
const d = EXT_CFG.defaults;
|
|
213
|
+
const map = {lang:'#lang', genre:'#genre', tone:'#tone', depth:'#depth', style:'#style', variant:'#variant'};
|
|
214
|
+
for(const [k,sel] of Object.entries(map)){ if(d[k] && $(sel)) $(sel).value = d[k]; }
|
|
215
|
+
const ck = {term:'c-term', note:'c-note', ext:'c-ext', format:'c-format', deai:'c-deai', ask:'c-ask'};
|
|
216
|
+
for(const [k,id] of Object.entries(ck)){ if(d[k] !== undefined && $('#'+id)) $('#'+id).checked = !!d[k]; }
|
|
217
|
+
}
|
|
218
|
+
// 断点续传:检测上次任务快照,有则提示恢复
|
|
219
|
+
setTimeout(promptResumeTask, 400);
|
|
220
|
+
})();
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/* ═══════════ 反馈(v4.26.0:提交 + 展示 + 本地暂存重发) ═══════════
|
|
2
|
+
入口:右下角常驻 #btn-fb(全功能区可见)
|
|
3
|
+
展示:项目进度页「反馈记录」卡 #fb-list
|
|
4
|
+
链路:浏览器 → 同源 /api/feedback/*(Pages 边缘)→ workers.dev → KV
|
|
5
|
+
本地:提交先落 tp.fb.log(仅存未发出的,网络不通也不丢,可在任务页重发) */
|
|
6
|
+
const FB_ERRS = [];
|
|
7
|
+
window.addEventListener('error', function(e){
|
|
8
|
+
const msg = String(e.message || e.type || '');
|
|
9
|
+
try{
|
|
10
|
+
FB_ERRS.push((new Date()).toTimeString().slice(0,8) + ' ' + msg);
|
|
11
|
+
if(FB_ERRS.length > 20) FB_ERRS.shift();
|
|
12
|
+
}catch(_){}
|
|
13
|
+
fbAutoReport('JS 报错', msg + (e.filename ? ' @' + String(e.filename).split('/').pop() + ':' + (e.lineno||0) : ''));
|
|
14
|
+
});
|
|
15
|
+
window.addEventListener('unhandledrejection', function(e){ /* v4.34.0:Promise 挂了也要记+报 */
|
|
16
|
+
const r = e && e.reason;
|
|
17
|
+
const msg = (r && (r.message || r)) || 'Promise rejected';
|
|
18
|
+
try{
|
|
19
|
+
FB_ERRS.push((new Date()).toTimeString().slice(0,8) + ' Promise: ' + msg);
|
|
20
|
+
if(FB_ERRS.length > 20) FB_ERRS.shift();
|
|
21
|
+
}catch(_){}
|
|
22
|
+
fbAutoReport('Promise 挂了', msg);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
/* ── v4.34.0 线上报错自动上报:有报错 → 立刻进反馈通道(线上 https 才发;本地无接口静默)→
|
|
26
|
+
开发端看门狗每分钟巡检 /api/feedback/list,发现新条目就在 DSH 聊天框提醒 ── */
|
|
27
|
+
let FB_AUTO_T = 0, FB_AUTO_SIG = '';
|
|
28
|
+
/* 反馈接口地址(方案A):真网页版(pages.dev,https)用同源 /api/feedback/*;插件/本地等
|
|
29
|
+
其它环境一律发到线上接口 https://transproof.pages.dev —— 这样朋友在插件里提交的反馈
|
|
30
|
+
也进同一份服务器日志。跨域已由反馈 Worker 的 Access-Control-Allow-Origin: * 放行。 */
|
|
31
|
+
const FB_LIVE = 'https://transproof.pages.dev';
|
|
32
|
+
const FB_ON_WEB = (location.protocol === 'https:' && location.hostname.endsWith('pages.dev'));
|
|
33
|
+
const FB_BASE = FB_ON_WEB ? '' : FB_LIVE;
|
|
34
|
+
function fbAutoReport(kind, msg){
|
|
35
|
+
try{
|
|
36
|
+
if(location.protocol !== 'https:') return; /* 本地没有 /api 通道,不发 */
|
|
37
|
+
const text = String(msg || '').trim();
|
|
38
|
+
if(!text) return;
|
|
39
|
+
const sig = kind + '|' + text.slice(0, 120);
|
|
40
|
+
if(sig === FB_AUTO_SIG) return; /* 同一条报错不重复发 */
|
|
41
|
+
const now = Date.now();
|
|
42
|
+
if(now - FB_AUTO_T < 30000) return; /* 30 秒节流,防刷屏 */
|
|
43
|
+
FB_AUTO_T = now; FB_AUTO_SIG = sig;
|
|
44
|
+
const d = new Date(), p2 = n => String(n).padStart(2, '0');
|
|
45
|
+
const localTime = d.getFullYear() + '-' + p2(d.getMonth()+1) + '-' + p2(d.getDate()) + 'T' + p2(d.getHours()) + ':' + p2(d.getMinutes());
|
|
46
|
+
fbPost({
|
|
47
|
+
desc: '🤖 自动报错(' + kind + '):' + text.slice(0, 400),
|
|
48
|
+
time: localTime, func: '其他',
|
|
49
|
+
where: '自动捕获 · ' + location.pathname + ' · ' + fbPageName(),
|
|
50
|
+
contact: '', ver: APP_VERSION, page: fbPageName(), path: location.pathname,
|
|
51
|
+
ua: navigator.userAgent.slice(0, 200),
|
|
52
|
+
lastErr: FB_ERRS.join(' | ').slice(0, 300)
|
|
53
|
+
}).catch(function(){ /* 发不出去就留在 FB_ERRS,手动反馈仍会带上 */ });
|
|
54
|
+
}catch(_){}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const FB_KEY = 'tp.fb.log';
|
|
58
|
+
const FB_FUNCS = ['运行与校对','导入与解析(PDF/Word/扫描OCR)','术语库','译词库','批量与智能扫描','导出与修订(Word)','设置与模型','开屏与界面','项目看板','其他'];
|
|
59
|
+
|
|
60
|
+
function fbLocal(){ const a = load(FB_KEY, []); return Array.isArray(a) ? a : []; }
|
|
61
|
+
function fbLocalSave(a){ save(FB_KEY, a.slice(0, 50)); }
|
|
62
|
+
function fbPageName(){ const b = document.querySelector('nav button.on'); return b ? b.textContent.trim().slice(0, 20) : ''; }
|
|
63
|
+
|
|
64
|
+
function fbMetaLine(){
|
|
65
|
+
const errs = FB_ERRS.length;
|
|
66
|
+
return '自动附带:v' + APP_VERSION + ' · 当前页:' + fbPageName()
|
|
67
|
+
+ ' · 最近 JS 报错 ' + errs + ' 条' + (errs ? '(一并发送,便于定位)' : '')
|
|
68
|
+
+ ' · 提交人不会显示给其他人';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function fbModalHtml(){
|
|
72
|
+
const d = new Date(), p = n => String(n).padStart(2, '0');
|
|
73
|
+
const now = d.getFullYear() + '-' + p(d.getMonth() + 1) + '-' + p(d.getDate()) + 'T' + p(d.getHours()) + ':' + p(d.getMinutes());
|
|
74
|
+
return `
|
|
75
|
+
<label class="f">问题描述 *</label>
|
|
76
|
+
<textarea id="fb-desc" rows="4" placeholder="哪里不对、你想要什么,大白话写就行"></textarea>
|
|
77
|
+
<div style="display:flex;gap:8px;flex-wrap:wrap;margin-top:12px">
|
|
78
|
+
<div style="flex:1 1 200px"><label class="f">出现时间 *</label><input type="datetime-local" id="fb-time" value="${now}"></div>
|
|
79
|
+
<div style="flex:1 1 220px"><label class="f">出现的功能 *</label><select id="fb-func">${FB_FUNCS.map(f => '<option>' + f + '</option>').join('')}</select></div>
|
|
80
|
+
</div>
|
|
81
|
+
<label class="f">出现的地点 · 操作路径 *</label>
|
|
82
|
+
<input id="fb-where" placeholder="例:使用指南 → 点「开始校对」之后">
|
|
83
|
+
<label class="f">联系方式(选填,方便回你)</label>
|
|
84
|
+
<input id="fb-contact" placeholder="微信 / 邮箱">
|
|
85
|
+
<div class="hint" id="fb-meta" style="margin-top:12px">${fbMetaLine()}</div>
|
|
86
|
+
<div style="display:flex;gap:8px;justify-content:flex-end;margin-top:16px">
|
|
87
|
+
<button class="btn gray" id="fb-cancel">取消</button>
|
|
88
|
+
<button class="btn pri" id="fb-submit">提交反馈</button>
|
|
89
|
+
</div>`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function fbCollect(){
|
|
93
|
+
const desc = ($('#fb-desc').value || '').trim();
|
|
94
|
+
const time = $('#fb-time').value || '';
|
|
95
|
+
const func = $('#fb-func').value || '';
|
|
96
|
+
const where = ($('#fb-where').value || '').trim();
|
|
97
|
+
const contact = ($('#fb-contact').value || '').trim();
|
|
98
|
+
if(!desc) return { err: '请先写一下问题描述' };
|
|
99
|
+
if(!time) return { err: '选一下出现时间' };
|
|
100
|
+
if(!where) return { err: '填一下出现的地点 / 操作路径,方便复现' };
|
|
101
|
+
return { rec: {
|
|
102
|
+
desc, time, func, where, contact,
|
|
103
|
+
ver: APP_VERSION,
|
|
104
|
+
page: fbPageName(),
|
|
105
|
+
path: location.pathname,
|
|
106
|
+
ua: navigator.userAgent.slice(0, 200),
|
|
107
|
+
lastErr: FB_ERRS.join(' | ').slice(0, 300)
|
|
108
|
+
} };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function fbPost(rec){
|
|
112
|
+
const r = await fetch(FB_BASE + '/api/feedback/submit', {
|
|
113
|
+
method: 'POST',
|
|
114
|
+
headers: { 'Content-Type': 'application/json' },
|
|
115
|
+
body: JSON.stringify(rec)
|
|
116
|
+
});
|
|
117
|
+
const j = await r.json();
|
|
118
|
+
if(!j.ok) throw new Error(j.err || 'submit rejected');
|
|
119
|
+
return j.id;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function fbSubmit(){
|
|
123
|
+
const got = fbCollect();
|
|
124
|
+
if(got.err) return toast(got.err);
|
|
125
|
+
const rec = got.rec;
|
|
126
|
+
const queue = fbLocal();
|
|
127
|
+
queue.unshift(Object.assign({ id: 'LOCAL-' + Date.now().toString(36).toUpperCase(), ts: Date.now() }, rec));
|
|
128
|
+
fbLocalSave(queue); // 先落本地,网络死了也不丢
|
|
129
|
+
try{
|
|
130
|
+
const id = await fbPost(rec);
|
|
131
|
+
const q2 = fbLocal().filter(x => x.id !== queue[0].id); // 发成功就从待发队列摘掉
|
|
132
|
+
fbLocalSave(q2);
|
|
133
|
+
closeModal();
|
|
134
|
+
toast('已提交 ✓ 编号 ' + id + '(「项目进度」页可查看)');
|
|
135
|
+
fbLoad();
|
|
136
|
+
}catch(e){
|
|
137
|
+
closeModal();
|
|
138
|
+
toast('网络没通,已存本地——到「项目进度」页点重发即可');
|
|
139
|
+
fbLoad();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function fbItemHtml(r, pending){
|
|
144
|
+
return '<div class="fb-item">'
|
|
145
|
+
+ '<div class="fb-h"><span class="fb-id">' + esc(String(r.id || '')) + '</span>'
|
|
146
|
+
+ (pending ? '<span class="fb-pend">未发出</span><button class="btn gray sm" data-fbresend="' + esc(String(r.id)) + '">重发</button>' : '')
|
|
147
|
+
+ '</div>'
|
|
148
|
+
+ '<div class="fb-h">' + [r.time, r.func, r.page ? ('页:' + r.page) : ''].filter(Boolean).map(s => esc(String(s))).join(' · ') + '</div>'
|
|
149
|
+
+ '<div class="fb-d">' + esc(String(r.desc || '')) + '</div>'
|
|
150
|
+
+ (r.where ? '<div class="fb-sub">路径:' + esc(String(r.where)) + '</div>' : '')
|
|
151
|
+
+ '</div>';
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async function fbLoad(){
|
|
155
|
+
const box = $('#fb-list');
|
|
156
|
+
if(!box) return;
|
|
157
|
+
let remote = [];
|
|
158
|
+
try{
|
|
159
|
+
const resp = await fetch(FB_BASE + '/api/feedback/list');
|
|
160
|
+
const j = await resp.json();
|
|
161
|
+
remote = (j && j.list) || [];
|
|
162
|
+
}catch(e){ /* 本地环境没有接口:只展示本地待发队列 */ }
|
|
163
|
+
const pend = fbLocal();
|
|
164
|
+
let html = pend.map(r => fbItemHtml(r, true)).join('') + remote.map(r => fbItemHtml(r, false)).join('');
|
|
165
|
+
if(!html) html = '<div class="hint">还没有记录。遇到问题点右下角「📩 反馈」提交,会出现在这里。</div>';
|
|
166
|
+
box.innerHTML = html;
|
|
167
|
+
const cnt = $('#fb-count');
|
|
168
|
+
if(cnt) cnt.textContent = '(' + (pend.length + remote.length) + ' 条)';
|
|
169
|
+
$$('#fb-list [data-fbresend]').forEach(b => { b.onclick = () => fbResend(b.getAttribute('data-fbresend')); });
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async function fbResend(id){
|
|
173
|
+
const queue = fbLocal();
|
|
174
|
+
const idx = queue.findIndex(x => x.id === id);
|
|
175
|
+
if(idx < 0) return toast('这条不在待发队列里了');
|
|
176
|
+
try{
|
|
177
|
+
const newId = await fbPost(queue[idx]);
|
|
178
|
+
const q2 = fbLocal();
|
|
179
|
+
const i2 = q2.findIndex(x => x.id === id);
|
|
180
|
+
if(i2 >= 0) q2.splice(i2, 1);
|
|
181
|
+
fbLocalSave(q2);
|
|
182
|
+
toast('已补发 ✓ 编号 ' + newId);
|
|
183
|
+
fbLoad();
|
|
184
|
+
}catch(e){
|
|
185
|
+
toast('还是没通,稍后再试(记录还在本地)');
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function fbOpen(){
|
|
190
|
+
modal('📩 提交问题 / 建议', fbModalHtml());
|
|
191
|
+
$('#fb-cancel').onclick = closeModal;
|
|
192
|
+
$('#fb-submit').onclick = fbSubmit;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/* ── 绑定与初始化 ── */
|
|
196
|
+
$('#btn-fb') && ($('#btn-fb').onclick = fbOpen);
|
|
197
|
+
$('#fb-refresh') && ($('#fb-refresh').onclick = fbLoad);
|
|
198
|
+
/* 只有线上(https)自动拉列表;本地 http 环境不发请求,避免无谓报错 */
|
|
199
|
+
setTimeout(fbLoad, 600);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/* ═══════════ 编辑/查找替换(v4.28.0)——校对结果与译文输出可编辑,Word 式查找替换 ═══════════ */
|
|
2
|
+
let EB = null;
|
|
3
|
+
function ebOpen(which){
|
|
4
|
+
if(EB) ebClose();
|
|
5
|
+
const target = which === 'ts' ? $('#ts-out') : $('#out');
|
|
6
|
+
if(!target) return;
|
|
7
|
+
if((which === 'ts' ? TS_LAST_OUT : LAST_OUT) === ''){ toast('还没有结果可编辑', 'w'); return; }
|
|
8
|
+
const wrap = document.createElement('div');
|
|
9
|
+
wrap.className = 'eb-wrap';
|
|
10
|
+
wrap.innerHTML = '<div class="eb-bar">' +
|
|
11
|
+
'<input class="eb-find" placeholder="查找">' +
|
|
12
|
+
'<input class="eb-repl" placeholder="替换为">' +
|
|
13
|
+
'<button class="btn gray sm eb-rep1">替换</button>' +
|
|
14
|
+
'<button class="btn gray sm eb-repall">全部替换</button>' +
|
|
15
|
+
'<span class="eb-count hint"></span>' +
|
|
16
|
+
'<span style="flex:1"></span>' +
|
|
17
|
+
'<button class="btn pri sm eb-save">💾 保存并重渲</button>' +
|
|
18
|
+
'<button class="btn gray sm eb-cancel">✕ 放弃修改</button>' +
|
|
19
|
+
'</div><textarea class="eb-ta" spellcheck="false"></textarea>';
|
|
20
|
+
target.parentNode.insertBefore(wrap, target);
|
|
21
|
+
const ta = wrap.querySelector('.eb-ta');
|
|
22
|
+
ta.value = which === 'ts' ? TS_LAST_OUT : LAST_OUT;
|
|
23
|
+
target.style.display = 'none';
|
|
24
|
+
EB = { which, target, wrap, ta, dirty: false };
|
|
25
|
+
const count = () => {
|
|
26
|
+
const q = wrap.querySelector('.eb-find').value;
|
|
27
|
+
const c = q ? ta.value.split(q).length - 1 : 0;
|
|
28
|
+
wrap.querySelector('.eb-count').textContent = q ? (c ? '找到 ' + c + ' 处' : '未找到') : '';
|
|
29
|
+
return c;
|
|
30
|
+
};
|
|
31
|
+
wrap.querySelector('.eb-find').oninput = count;
|
|
32
|
+
wrap.querySelector('.eb-rep1').onclick = () => {
|
|
33
|
+
const q = wrap.querySelector('.eb-find').value, r = wrap.querySelector('.eb-repl').value;
|
|
34
|
+
if(!q){ toast('先填「查找」', 'w'); return; }
|
|
35
|
+
const i = ta.value.indexOf(q);
|
|
36
|
+
if(i < 0){ toast('没找到', 'w'); return; }
|
|
37
|
+
ta.value = ta.value.slice(0, i) + r + ta.value.slice(i + q.length);
|
|
38
|
+
EB.dirty = true; count();
|
|
39
|
+
};
|
|
40
|
+
wrap.querySelector('.eb-repall').onclick = () => {
|
|
41
|
+
const q = wrap.querySelector('.eb-find').value, r = wrap.querySelector('.eb-repl').value;
|
|
42
|
+
if(!q){ toast('先填「查找」', 'w'); return; }
|
|
43
|
+
const c = count();
|
|
44
|
+
if(!c){ toast('没找到', 'w'); return; }
|
|
45
|
+
ta.value = ta.value.split(q).join(r);
|
|
46
|
+
EB.dirty = true; count();
|
|
47
|
+
toast('已替换 ' + c + ' 处');
|
|
48
|
+
};
|
|
49
|
+
wrap.querySelector('.eb-save').onclick = ebSave;
|
|
50
|
+
wrap.querySelector('.eb-cancel').onclick = () => ebClose();
|
|
51
|
+
ta.focus();
|
|
52
|
+
}
|
|
53
|
+
function ebSave(){
|
|
54
|
+
if(!EB) return;
|
|
55
|
+
const v = EB.ta.value;
|
|
56
|
+
if(EB.which === 'ts'){ TS_LAST_OUT = v; $('#ts-out').innerHTML = md(v); }
|
|
57
|
+
else {
|
|
58
|
+
LAST_OUT = v;
|
|
59
|
+
$('#out').innerHTML = md(v);
|
|
60
|
+
collapseSections(); markErrorLines(); renderAuditControls(); paintErrFixSpans();
|
|
61
|
+
}
|
|
62
|
+
saveTask();
|
|
63
|
+
ebClose();
|
|
64
|
+
toast('已保存');
|
|
65
|
+
}
|
|
66
|
+
function ebClose(){
|
|
67
|
+
if(!EB) return;
|
|
68
|
+
EB.target.style.display = '';
|
|
69
|
+
EB.wrap.remove();
|
|
70
|
+
EB = null;
|
|
71
|
+
}
|
|
72
|
+
$('#btn-out-edit') && ($('#btn-out-edit').onclick = () => ebOpen('out'));
|
|
73
|
+
$('#btn-ts-edit') && ($('#btn-ts-edit').onclick = () => ebOpen('ts'));
|
|
74
|
+
// 测试 seam
|
|
75
|
+
window.__EB = { setTs: (t) => { TS_LAST_OUT = String(t || ''); $('#ts-out').innerHTML = md(TS_LAST_OUT); } };
|