mirror of
https://github.com/eternity4719/HowToLiveBetter.git
synced 2026-11-20 08:32:18 +08:00
feat(web): 自查结果支持复制行动清单
This commit is contained in:
+44
-2
@@ -103,6 +103,11 @@ html.dark .btn{color:#1b1b1f}
|
||||
.top3{margin:8px 0 0;padding-left:22px}
|
||||
.top3 li{margin:6px 0}
|
||||
.top3 .why{color:var(--t2);font-size:13.5px}
|
||||
.copy-tools{margin-top:12px}
|
||||
.copy-status{margin:8px 0 0;color:var(--t2);font-size:14px}
|
||||
.copy-tools label{display:block;margin:12px 0 4px;font-size:14px}
|
||||
.copy-tools textarea{display:block;width:100%;padding:12px;border:1px solid var(--divider);border-radius:8px;background:var(--bg-soft);color:var(--t1);font:inherit;font-size:14px;resize:vertical}
|
||||
.copy-tools button:disabled{cursor:wait;opacity:.65}
|
||||
.card{scroll-margin-top:72px}
|
||||
.done-list{color:var(--t2);font-size:14px;padding-left:20px}
|
||||
#status{color:var(--t2);padding:40px 0;text-align:center}
|
||||
@@ -393,16 +398,30 @@ function renderOut(){
|
||||
|
||||
// 先做这三件:性价比最高的排前;同档里先挑不用改习惯的
|
||||
const top = no.slice(0, 3);
|
||||
const topTitle = `先做这${top.length === 3 ? '三' : top.length === 2 ? '两' : '一'}件`;
|
||||
const alsoOf = q => (q.also || []).map(a => find(a.sec, a.key)).filter(Boolean);
|
||||
let h = '';
|
||||
if (top.length) h += `<h2>先做这${top.length === 3 ? '三' : top.length === 2 ? '两' : '一'}件<small>没做到的里性价比最高的</small></h2><ol class="top3">`
|
||||
+ top.map(q => `<li><a href="#c-${q.entry.sec}-${q.entry.n}">${esc(plain(q.entry.title))}</a> <span class="why">性价比${q.entry.ratio},证据 ${q.entry.grade} 级,${PILES.find(p => p.will === q.entry.will)?.name ?? ''}</span></li>`).join('') + '</ol>';
|
||||
if (top.length) h += `<h2>${topTitle}<small>没做到的里性价比最高的</small></h2><ol class="top3">`
|
||||
+ top.map(q => `<li><a href="#c-${q.entry.sec}-${q.entry.n}">${esc(plain(q.entry.title))}</a> <span class="why">性价比${q.entry.ratio},证据 ${q.entry.grade} 级,${PILES.find(p => p.will === q.entry.will)?.name ?? ''}</span></li>`).join('') + '</ol>'
|
||||
+ `<div class="copy-tools">
|
||||
<button class="btn" id="copy-actions" type="button">复制这几件事</button>
|
||||
<p class="copy-status" id="copy-status" role="status" aria-live="polite" aria-atomic="true"></p>
|
||||
<div id="copy-fallback" hidden>
|
||||
<label for="copy-text">行动清单</label>
|
||||
<textarea id="copy-text" rows="10" readonly aria-describedby="copy-status"></textarea>
|
||||
</div>
|
||||
</div>`;
|
||||
for (const p of PILES){
|
||||
const list = no.filter(q => q.entry.will === p.will);
|
||||
if (!list.length) continue;
|
||||
h += `<h2>${p.name}(${list.length} 项)<small>${p.sub}</small></h2>` + list.map(q => card(q.entry, alsoOf(q))).join('');
|
||||
}
|
||||
document.getElementById('todo').innerHTML = h;
|
||||
if (top.length) document.getElementById('copy-text').value = `高性价比人生指南 · ${topTitle}\n\n` + top.map(({entry:e}) =>
|
||||
`- [ ] ${plain(e.title)}\n`
|
||||
+ ` 性价比${e.ratio},证据 ${e.grade} 级,${PILES.find(p => p.will === e.will)?.name ?? ''}${e.dispute ? ',有争议(先看原条目的备注)' : ''}\n`
|
||||
+ ` 要花的:${plain(e.cost)}\n`
|
||||
+ ` https://eternity4719.github.io/HowToLiveBetter/#e-${e.sec}-${e.n}`).join('\n\n');
|
||||
document.getElementById('done').innerHTML = yes.map(q =>
|
||||
`<li><a href="./#e-${q.entry.sec}-${q.entry.n}">${esc(plain(q.entry.title))}</a></li>`).join('');
|
||||
document.getElementById('done-h').hidden = !yes.length;
|
||||
@@ -414,6 +433,29 @@ function show(which){
|
||||
scrollTo(0, 0);
|
||||
}
|
||||
|
||||
document.getElementById('todo').addEventListener('click', async ev => {
|
||||
const b = ev.target.closest('#copy-actions'); if (!b) return;
|
||||
const status = document.getElementById('copy-status'), fallback = document.getElementById('copy-fallback');
|
||||
const text = document.getElementById('copy-text');
|
||||
b.disabled = true;
|
||||
fallback.hidden = true;
|
||||
status.textContent = '正在复制…';
|
||||
try {
|
||||
await navigator.clipboard.writeText(text.value);
|
||||
if (b.isConnected && !document.getElementById('out').hidden) status.textContent = '已复制,可以粘贴到备忘录或待办应用。';
|
||||
} catch (err) {
|
||||
// 等待剪贴板权限时可能已经返回改答案,不把焦点拉回旧结果。
|
||||
if (!b.isConnected || document.getElementById('out').hidden) return;
|
||||
fallback.hidden = false;
|
||||
status.textContent = '无法自动复制,请在下方手动复制清单。';
|
||||
text.focus();
|
||||
text.select();
|
||||
text.scrollTop = 0;
|
||||
} finally {
|
||||
b.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('qs').addEventListener('click', ev => {
|
||||
const mb = ev.target.closest('button[data-mod]');
|
||||
if (mb) { ans['mod:' + mb.dataset.mod] = modOn(mb.dataset.mod) ? 'off' : undefined; save(); renderAsk(); return; }
|
||||
|
||||
Reference in New Issue
Block a user