Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extension/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,7 @@ function cleanupReaderFloatingArtifacts(playerHost = state.readingPlayerHost) {
// Every entry into 专注模式 (the URL, a SPA video change, the popup): a failure is red on the page, the same sentence.
function startReaderMode() {
enterReaderMode().catch((error) => {
setReadingNotice(`${MdgErrors.TEXT.readerStartFailed}:${MdgErrors.messageOf(error)}`, { error: true });
setReadingNotice(MdgErrors.reloaded(error) ? MdgErrors.TEXT.reloaded : `${MdgErrors.TEXT.readerStartFailed}:${MdgErrors.messageOf(error)}`, { error: true });
});
}

Expand Down
5 changes: 3 additions & 2 deletions extension/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@
nothingToCopy: "没有可复制的内容",
nothingToDownload: "没有可下载的内容",
nothingToWrite: "没有可写入 Obsidian 的内容",
// A copy to the clipboard failed (popup, side panel, 摘读记录, 分拣台); 「:原因」 follows, noClipboard without one.
// A copy to the clipboard failed (popup, side panel, 摘读记录, 分拣台); 「:原因」 follows (noClipboard when the clipboard refused).
copyFailed: "复制失败",
// 下载 .md failed (side panel, 摘读记录); 「:原因」 follows.
downloadFailed: "下载失败",
noClipboard: "无法访问剪贴板",
// The page lost focus while the note was prepared, or the browser refused (Chrome's English NotAllowedError).
noClipboard: "无法访问剪贴板,点一下页面再试",
// The side panel while the video page reads the subtitle for it.
subtitleReading: "正在读取视频字幕…",
// 分拣台's 收藏夹设置 / 关注设置 and their AI 参数; a failure is followed by 「:原因」.
Expand Down
2 changes: 1 addition & 1 deletion extension/history/history.selftest.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ assert.ok(/<dialog id="confirmDialog"[\s\S]*id="confirmTitle"[\s\S]*id="confirmB
// B4: failures are red: a copy, and opening the side panel from 继续问.
ctx.navigator.clipboard.writeText = async () => { throw new Error("无法访问剪贴板"); };
await act("copy");
assert.deepStrictEqual([els.status.textContent, red], ["复制失败:无法访问剪贴板", true]);
assert.deepStrictEqual([els.status.textContent, red], ["复制失败:无法访问剪贴板,点一下页面再试", true]);
ctx.chrome.sidePanel = { open: async () => { throw new Error("没有窗口"); } };
await act("ask");
assert.deepStrictEqual([els.status.textContent, red], ["打开侧边栏失败:没有窗口", true]);
Expand Down
3 changes: 2 additions & 1 deletion extension/note-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
try {
const resp = note || (await resolve(kind, request, send, isStale, dialogs));
if (resp.stop) return { ok: true, done: false, text: resp.stop, remedies: [] };
if (kind === "copy") await navigator.clipboard.writeText(resp.markdown);
// Any refusal says noClipboard, not Chrome's English ("Document is not focused"); no cause, its code is a DOMException's.
if (kind === "copy") await navigator.clipboard.writeText(resp.markdown).catch(() => Promise.reject(new Error(MdgErrors.TEXT.noClipboard)));
if (kind === "download") MdgDownload.text(resp.filename, resp.markdown);
return { ok: true, done: true, text: DONE[kind] || resp.text, remedies: [] };
} catch (error) {
Expand Down
11 changes: 6 additions & 5 deletions extension/note-actions.selftest.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,12 @@ const plain = (r) => JSON.parse(JSON.stringify(r));
const r = await run(kind, { request, send: fail({ ok: false, error: T.nothingToWrite, code: "NOTE_EMPTY" }) });
assert.deepStrictEqual([r.ok, r.text, [...r.remedies]], [false, want, []], kind);
}
// The clipboard refused: 复制失败, 无法访问剪贴板 when it gave no words.
ctx.navigator.clipboard.writeText = async () => { throw new Error(""); };
assert.strictEqual((await run("copy", { note: { markdown: "x" } })).text, `${T.copyFailed}:${T.noClipboard}`);
ctx.navigator.clipboard.writeText = async () => { throw new Error("没有权限"); };
assert.strictEqual((await run("copy", { note: { markdown: "x" } })).text, `${T.copyFailed}:没有权限`);
// The clipboard refused: 复制失败:无法访问剪贴板, never Chrome's English, with or without words.
for (const message of ["", "Failed to execute 'writeText' on 'Clipboard': Document is not focused."]) {
ctx.navigator.clipboard.writeText = async () => { throw Object.assign(new Error(message), { name: "NotAllowedError", code: 0 }); };
const r = await run("copy", { note: { markdown: "x" } });
assert.deepStrictEqual([r.text, r.code], [`${T.copyFailed}:${T.noClipboard}`, undefined], message);
}
// The extension reloaded under the video page: its own sentence.
assert.strictEqual((await run("write", { request, send: async () => { throw new Error("Extension context invalidated."); } })).text, T.reloaded);

Expand Down
2 changes: 1 addition & 1 deletion extension/sidepanel.selftest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ const tick = () => new Promise((r) => setImmediate(r));
// C350: a reply's 复制 Markdown says 已复制 Markdown, like the export menu's.
ctx.navigator.clipboard = { writeText: async () => {} };
await ctx.copyMarkdown("x");
assert.deepStrictEqual(notices, [["复制失败:无法访问剪贴板", true], ["已复制 Markdown", false]]);
assert.deepStrictEqual(notices, [["复制失败:无法访问剪贴板,点一下页面再试", true], ["已复制 Markdown", false]]);
delete ctx.navigator.clipboard;
[ctx.showConversationContextNotice, ctx.chrome.runtime.sendMessage] = prev;
}
Expand Down
2 changes: 1 addition & 1 deletion extension/triage/triage.selftest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3996,7 +3996,7 @@ const unfavOnlyOf = (d) => Object.fromEntries(Object.entries(d).filter(([, v]) =
t.el.writeFormat.value = "digest";
t.navigator = { clipboard: { writeText: async () => { throw new Error("没有权限"); } } };
await t.exportDigest("copy");
assert.ok(t.el.writeProgress.textContent === "复制失败:没有权限" && cls.has("fail-text"), "copy failure in red");
assert.ok(t.el.writeProgress.textContent === "复制失败:无法访问剪贴板,点一下页面再试" && cls.has("fail-text"), "copy failure in red");
handlers["triage-export"] = (m) => ({ ok: true, data: { path: `库/${m.filename}`, text: `已写入 Obsidian:库/${m.filename}` } });
await t.exportDigest("obsidian");
assert.ok(/^已写入 Obsidian:库\/B站摘录-/.test(t.el.writeProgress.textContent) && !cls.has("fail-text"), t.el.writeProgress.textContent);
Expand Down
Loading