Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix(extension): stabilize clip menus and clarify Zhihu notes

tianma-if8f08c89c1ba3
diff --git a/apps/extension/FIREFOX_STORE_LISTING.md b/apps/extension/FIREFOX_STORE_LISTING.md
index a0621a0c..ef9a7d9a 100644
--- a/apps/extension/FIREFOX_STORE_LISTING.md
+++ b/apps/extension/FIREFOX_STORE_LISTING.md
@@ -25,7 +25,7 @@ EdgeEver Web Clipper saves the current webpage, selected text, a right-clicked i
- Send content directly to your instance without an EdgeEver-operated relay.
- No advertising, analytics, tracking, or telemetry.
-Before using the extension, enter your EdgeEver instance URL and API token in the extension settings. The extension reads and sends page content only after you click **Clip current page**, **Save selection to EdgeEver**, **Save image to EdgeEver**, **Save this post to EdgeEver**, **Save this Xiaohongshu note to EdgeEver**, **Save this Zhihu answer or article to EdgeEver**, or **Save this repository to EdgeEver**.
+Before using the extension, enter your EdgeEver instance URL and API token in the extension settings. The extension reads and sends page content only after you click **Clip current page**, **Save selection to EdgeEver**, **Save image to EdgeEver**, **Save this post to EdgeEver**, **Save this Xiaohongshu note to EdgeEver**, **Save Zhihu content to EdgeEver**, or **Save this repository to EdgeEver**.
## Data collection and transmission
@@ -47,7 +47,7 @@ The project maintainers do not receive or retain this data. Instance settings ar
8. Open one X post page, right-click the post text (not a photo), choose **Save this post to EdgeEver**, and verify the note contains the post text and the post link.
9. Open one GitHub repository page, right-click the description or README text, choose **Save this repository to EdgeEver**, and verify the note contains the repository address and description.
10. Open one Xiaohongshu note, right-click the note text (not a photo), choose **Save this Xiaohongshu note to EdgeEver**, and verify the note contains the title, text, and source link.
-11. Open one Zhihu answer or article, right-click the text (not a photo), choose **Save this Zhihu answer or article to EdgeEver**, and verify the note contains the title, text, and source link.
+11. Open one Zhihu answer or article, right-click the text (not a photo), choose **Save Zhihu content to EdgeEver**, and verify the note contains the title, text, and source link.
12. Verify the created notes in the review EdgeEver instance.
Restricted browser pages, extension stores, built-in PDF viewers, and other privileged pages cannot be captured.
@@ -85,4 +85,4 @@ EdgeEver 网页剪藏插件可将当前网页、选中的文字、右键选中
- 数据直接发送到用户自己的实例,不经过 EdgeEver 中转服务。
- 不包含广告、分析、追踪或遥测。
-使用前,请在插件设置中填写 EdgeEver 实例地址和 API Token。插件只会在用户点击“剪藏当前网页”,或选择“保存选中文字到 EdgeEver”“保存图片到 EdgeEver”“保存这条推文到 EdgeEver”“保存这篇小红书笔记到 EdgeEver”“保存这篇知乎回答或文章到 EdgeEver”后读取并发送网页内容。
+使用前,请在插件设置中填写 EdgeEver 实例地址和 API Token。插件只会在用户点击“剪藏当前网页”,或选择“保存选中文字到 EdgeEver”“保存图片到 EdgeEver”“保存这条推文到 EdgeEver”“保存这篇小红书笔记到 EdgeEver”“保存知乎内容到 EdgeEver”后读取并发送网页内容。
diff --git a/apps/extension/README.md b/apps/extension/README.md
index 69a6fa3d..21b81e3c 100644
--- a/apps/extension/README.md
+++ b/apps/extension/README.md
@@ -12,7 +12,7 @@ Chrome, Edge, and Firefox Manifest V3 extension for saving the current webpage,
- Select text on a page, right-click, and choose **Save selection to EdgeEver**. That passage is saved as a new note in the default notebook, with the source page linked underneath. The rest of the page is not included.
- On X, right-click the post text and choose **Save this post to EdgeEver**. The post text, author, time, and photos already shown in that post are saved into one note. Text folded behind Show more is expanded first, so a long post is saved in full. Right-clicking a photo saves that image instead, so the command stays on the top-level menu. A single-post page can be saved immediately. On a timeline, the extension asks once for access to X so it can remember the post under the pointer.
- On Xiaohongshu, right-click the note text and choose **Save this Xiaohongshu note to EdgeEver**. The title, text, author, time, location, and photos go into one note. Comments are left out. Right-clicking a photo saves that image instead. An open note can be saved immediately. On the feed, the extension asks once for access to Xiaohongshu so it can remember the note under the pointer; open that note before saving if its full text is not on the page.
-- On Zhihu, right-click the answer or article text and choose **Save this Zhihu answer or article to EdgeEver**. The title, author, full text, and photos go into one note. Comments are left out. Right-clicking a photo saves that image instead. An open answer or article can be saved immediately. On the home feed or a question page, the extension remembers the item under the pointer; if that listener is not running yet, right-click the same text once more.
+- On Zhihu, right-click the answer or article text and choose **Save Zhihu content to EdgeEver**. The title, author, full text, and photos go into one note. Comments are left out. Right-clicking a photo saves that image instead. An open answer or article can be saved immediately. On the home feed or a question page, the extension remembers the item under the pointer; if that listener is not running yet, right-click the same text once more.
- On a GitHub repository page or code tree, right-click the page background, the description, or the README text and choose **Save this repository to EdgeEver**. The note keeps the repository address, the About text, and the homepage, language, license, and topics when the page shows them. An empty About falls back to the README's first paragraph. Issue, discussion, and single-file pages are left unsaved. The toolbar action uses the same card on those repository pages. Right-clicking a link or an image keeps the existing selection and image commands, so this one stays on the top-level menu.
- When the page cannot hand over the image bytes, the extension asks once for access to that image's site. After that, later images from the same site save directly.
- Create a searchable EdgeEver memo with the source URL and a `web-clip` tag.
diff --git a/apps/extension/STORE_LISTING.md b/apps/extension/STORE_LISTING.md
index 04df9a98..8e7b48e3 100644
--- a/apps/extension/STORE_LISTING.md
+++ b/apps/extension/STORE_LISTING.md
@@ -89,11 +89,11 @@ Save the current webpage, user-selected text, a user-chosen image, one X post, o
### Permission justifications
-- `activeTab`: Read the active page only after the user clicks the extension's save action or chooses Save selection to EdgeEver, Save image to EdgeEver, Save this post to EdgeEver, Save this Xiaohongshu note to EdgeEver, Save this Zhihu answer or article to EdgeEver, or Save this repository to EdgeEver.
+- `activeTab`: Read the active page only after the user clicks the extension's save action or chooses Save selection to EdgeEver, Save image to EdgeEver, Save this post to EdgeEver, Save this Xiaohongshu note to EdgeEver, Save Zhihu content to EdgeEver, or Save this repository to EdgeEver.
- `contextMenus`: Add one top-level item for the thing the user right-clicked: selected text, an image, an X post, a Xiaohongshu note, a Zhihu answer or article, or a GitHub repository page. It runs only after the user selects that item.
- `scripting`: Inject the packaged capture script into the active page after the user initiates a capture.
- `storage`: Store the user's EdgeEver instance URL, API token, and default notebook ID locally.
-- Optional host permissions: API calls go only to the EdgeEver instance the user approves. If a page cannot provide an image file, the extension asks for that image's site, or for all sites when the user chooses that option, and uses the access only to download the chosen image. Saving from an X timeline asks for access to X so the extension can remember the post under the pointer. That script only records the target and runs after the user allows it. Saving from a Xiaohongshu feed asks for Xiaohongshu for the same reason. An open note page can be saved without that extra permission. On Zhihu, a content script remembers the answer or article under the pointer and does not send the page anywhere. The full text is read only after the user chooses Save this Zhihu answer or article to EdgeEver, and it is sent only to the user's instance. If that listener is missing, the extension asks once for Zhihu and then asks the user to right-click the same text again.
+- Optional host permissions: API calls go only to the EdgeEver instance the user approves. If a page cannot provide an image file, the extension asks for that image's site, or for all sites when the user chooses that option, and uses the access only to download the chosen image. Saving from an X timeline asks for access to X so the extension can remember the post under the pointer. That script only records the target and runs after the user allows it. Saving from a Xiaohongshu feed asks for Xiaohongshu for the same reason. An open note page can be saved without that extra permission. On Zhihu, a content script remembers the answer or article under the pointer and does not send the page anywhere. The full text is read only after the user chooses Save Zhihu content to EdgeEver, and it is sent only to the user's instance. If that listener is missing, the extension asks once for Zhihu and then asks the user to right-click the same text again.
Each permission justification field accepts at most 1,000 characters. The host text above is the wording saved with the 0.1.9 draft.
diff --git a/apps/extension/context-menus.test.mjs b/apps/extension/context-menus.test.mjs
new file mode 100644
index 00000000..61372998
--- /dev/null
+++ b/apps/extension/context-menus.test.mjs
@@ -0,0 +1,61 @@
+import { expect, test } from "bun:test";
+
+test("registers context menus on install, not on background startup", async () => {
+ const installedListeners = [];
+ const created = [];
+ let removeCount = 0;
+ const previousChrome = globalThis.chrome;
+ globalThis.chrome = {
+ i18n: { getMessage: (key) => key },
+ runtime: {
+ onInstalled: { addListener: (listener) => installedListeners.push(listener) },
+ onMessage: { addListener: () => {} },
+ lastError: undefined,
+ },
+ contextMenus: {
+ onClicked: { addListener: () => {} },
+ removeAll: (callback) => {
+ removeCount += 1;
+ callback();
+ },
+ create: (options, callback) => {
+ created.push(options);
+ callback();
+ },
+ },
+ windows: { onRemoved: { addListener: () => {} } },
+ };
+
+ try {
+ await import("./src/background.ts");
+ expect(installedListeners).toHaveLength(1);
+ expect(removeCount).toBe(0);
+ expect(created).toHaveLength(0);
+
+ installedListeners[0]({ reason: "update" });
+ expect(removeCount).toBe(1);
+ expect(created.map((item) => item.id)).toEqual([
+ "save-selection",
+ "save-image",
+ "save-tweet",
+ "save-github-repo",
+ "save-xhs",
+ "save-zhihu",
+ ]);
+ expect(created.find((item) => item.id === "save-xhs")).toMatchObject({
+ contexts: ["page", "video"],
+ documentUrlPatterns: ["https://www.xiaohongshu.com/*", "https://xiaohongshu.com/*"],
+ });
+ expect(created.find((item) => item.id === "save-zhihu")).toMatchObject({
+ contexts: ["page", "video"],
+ documentUrlPatterns: [
+ "https://www.zhihu.com/*",
+ "https://zhihu.com/*",
+ "https://zhuanlan.zhihu.com/*",
+ "https://www.zhuanlan.zhihu.com/*",
+ ],
+ });
+ } finally {
+ globalThis.chrome = previousChrome;
+ }
+});
diff --git a/apps/extension/options.html b/apps/extension/options.html
index 88731275..fde7e7a3 100644
--- a/apps/extension/options.html
+++ b/apps/extension/options.html
@@ -13,7 +13,7 @@
<p class="hint" data-i18n="tweetSaveHint">On X, right-click a post and choose “Save this post to EdgeEver”. The visible text and photos go into one new note in the same notebook.</p>
<p class="hint" data-i18n="githubRepoSaveHint">On a GitHub repository page or code tree, right-click the page background, the description, or the README text and choose “Save this repository to EdgeEver”. The address and description are saved as a new note in the default notebook selected above.</p>
<p class="hint" data-i18n="xhsSaveHint">On Xiaohongshu, right-click the note text and choose “Save this Xiaohongshu note to EdgeEver”. The title, text, and photos go into one new note. Comments are left out.</p>
- <p class="hint" data-i18n="zhihuSaveHint">On Zhihu, right-click the answer or article text and choose “Save this Zhihu answer or article to EdgeEver”. The title, author, text, and photos go into one new note. Comments are left out.</p>
+ <p class="hint" data-i18n="zhihuSaveHint">On Zhihu, right-click the answer or article text and choose “Save Zhihu content to EdgeEver”. The title, author, text, and photos go into one new note. Comments are left out.</p>
<form id="settings-form">
<label>
<span data-i18n="instanceAddress">EdgeEver instance URL</span>
diff --git a/apps/extension/package.json b/apps/extension/package.json
index 8e222a25..9479eb8d 100644
--- a/apps/extension/package.json
+++ b/apps/extension/package.json
@@ -1,6 +1,6 @@
{
"name": "@edgeever/extension",
- "version": "0.1.9",
+ "version": "0.1.13",
"private": true,
"type": "module",
"scripts": {
@@ -9,9 +9,10 @@
"dev": "vite --config vite.config.ts",
"lint:firefox": "web-ext lint --source-dir dist-firefox --output text",
"package:firefox": "bun run build:firefox && bun run lint:firefox && web-ext build --source-dir dist-firefox --artifacts-dir web-ext-artifacts --overwrite-dest",
- "test": "bun test manifest.test.mjs image-clip.test.mjs tweet-clip.test.mjs selection-clip.test.mjs github-repo.test.mjs xhs-clip.test.mjs zhihu-clip.test.mjs"
+ "test": "bun test manifest.test.mjs context-menus.test.mjs image-clip.test.mjs tweet-clip.test.mjs selection-clip.test.mjs github-repo.test.mjs xhs-clip.test.mjs zhihu-clip.test.mjs"
},
"dependencies": {
+ "@mixmark-io/domino": "2.2.0",
"@mozilla/readability": "^0.6.0",
"turndown": "^7.2.4"
},
diff --git a/apps/extension/public/_locales/en/messages.json b/apps/extension/public/_locales/en/messages.json
index df2f2351..9a2dc958 100644
--- a/apps/extension/public/_locales/en/messages.json
+++ b/apps/extension/public/_locales/en/messages.json
@@ -397,10 +397,25 @@
"message": "Location"
},
"saveZhihuToEdgeEver": {
- "message": "Save this Zhihu answer or article to EdgeEver"
+ "message": "Save Zhihu content to EdgeEver"
+ },
+ "zhihuQuestionLabel": {
+ "message": "Question"
+ },
+ "zhihuArticleLabel": {
+ "message": "Article"
+ },
+ "zhihuAuthorLabel": {
+ "message": "Author:"
+ },
+ "zhihuAnswerLabel": {
+ "message": "Answer"
+ },
+ "zhihuArticleBodyLabel": {
+ "message": "Body"
},
"zhihuSaveHint": {
- "message": "On Zhihu, right-click the answer or article text and choose “Save this Zhihu answer or article to EdgeEver”. The title, author, text, and photos go into one new note. Comments are left out. Right-clicking a photo still saves that image only."
+ "message": "On Zhihu, right-click the answer or article text and choose “Save Zhihu content to EdgeEver”. The title, author, text, and photos go into one new note. Comments are left out. Right-clicking a photo still saves that image only."
},
"savingZhihu": {
"message": "Saving this Zhihu answer or article…"
@@ -436,6 +451,6 @@
"message": "Zhihu answer or article"
},
"zhihuSaveWindowTitle": {
- "message": "Save this Zhihu answer or article to EdgeEver"
+ "message": "Save Zhihu content to EdgeEver"
}
}
diff --git a/apps/extension/public/_locales/ja/messages.json b/apps/extension/public/_locales/ja/messages.json
index 654a5a88..755c60b9 100644
--- a/apps/extension/public/_locales/ja/messages.json
+++ b/apps/extension/public/_locales/ja/messages.json
@@ -397,10 +397,25 @@
"message": "場所"
},
"saveZhihuToEdgeEver": {
- "message": "この知乎の回答または記事を EdgeEver に保存"
+ "message": "知乎の内容を EdgeEver に保存"
+ },
+ "zhihuQuestionLabel": {
+ "message": "質問"
+ },
+ "zhihuArticleLabel": {
+ "message": "記事"
+ },
+ "zhihuAuthorLabel": {
+ "message": "著者:"
+ },
+ "zhihuAnswerLabel": {
+ "message": "回答"
+ },
+ "zhihuArticleBodyLabel": {
+ "message": "本文"
},
"zhihuSaveHint": {
- "message": "知乎で回答または記事の本文を右クリックし、「この知乎の回答または記事を EdgeEver に保存」を選びます。タイトル、著者、本文、画像が 1 件のノートになります。コメントは含めません。画像を右クリックした場合は、その画像だけを保存します。"
+ "message": "知乎で回答または記事の本文を右クリックし、「知乎の内容を EdgeEver に保存」を選びます。タイトル、著者、本文、画像が 1 件のノートになります。コメントは含めません。画像を右クリックした場合は、その画像だけを保存します。"
},
"savingZhihu": {
"message": "この知乎の回答または記事を保存しています…"
@@ -436,6 +451,6 @@
"message": "知乎の回答または記事"
},
"zhihuSaveWindowTitle": {
- "message": "この知乎の回答または記事を EdgeEver に保存"
+ "message": "知乎の内容を EdgeEver に保存"
}
}
diff --git a/apps/extension/public/_locales/zh_CN/messages.json b/apps/extension/public/_locales/zh_CN/messages.json
index 64416768..d360a684 100644
--- a/apps/extension/public/_locales/zh_CN/messages.json
+++ b/apps/extension/public/_locales/zh_CN/messages.json
@@ -397,10 +397,25 @@
"message": "地点"
},
"saveZhihuToEdgeEver": {
- "message": "保存这篇知乎回答或文章到 EdgeEver"
+ "message": "保存知乎内容到 EdgeEver"
+ },
+ "zhihuQuestionLabel": {
+ "message": "问题"
+ },
+ "zhihuArticleLabel": {
+ "message": "文章"
+ },
+ "zhihuAuthorLabel": {
+ "message": "作者:"
+ },
+ "zhihuAnswerLabel": {
+ "message": "回答"
+ },
+ "zhihuArticleBodyLabel": {
+ "message": "正文"
},
"zhihuSaveHint": {
- "message": "在知乎回答或文章的正文上右键,选择“保存这篇知乎回答或文章到 EdgeEver”。标题、作者、正文和图片会存成一条新笔记,评论不会写入。右键图片仍然只保存这张图片。"
+ "message": "在知乎回答或文章的正文上右键,选择“保存知乎内容到 EdgeEver”。标题、作者、正文和图片会存成一条新笔记,评论不会写入。右键图片仍然只保存这张图片。"
},
"savingZhihu": {
"message": "正在保存这篇知乎内容……"
@@ -436,6 +451,6 @@
"message": "一篇知乎内容"
},
"zhihuSaveWindowTitle": {
- "message": "保存这篇知乎回答或文章到 EdgeEver"
+ "message": "保存知乎内容到 EdgeEver"
}
}
diff --git a/apps/extension/src/background.ts b/apps/extension/src/background.ts
index b1621cbc..4a6267f1 100644
--- a/apps/extension/src/background.ts
+++ b/apps/extension/src/background.ts
@@ -908,6 +908,7 @@ const saveLocatedZhihu = async (
if (stored) images.push({ ...stored, sourceUrl: image.url });
}
await saveCapturedZhihuNote(imageNoteClient(settings), {
+ kind: note.kind,
notebookId: settings.notebookId,
title: zhihuNoteTitle({
title: note.title,
@@ -925,6 +926,11 @@ const saveLocatedZhihu = async (
sourceLabel: t("sourceLabel"),
capturedAtLabel: t("capturedAtLabel"),
timeLabel: t("tweetTimeLabel"),
+ questionLabel: t("zhihuQuestionLabel"),
+ articleLabel: t("zhihuArticleLabel"),
+ authorLabel: t("zhihuAuthorLabel"),
+ answerLabel: t("zhihuAnswerLabel"),
+ articleBodyLabel: t("zhihuArticleBodyLabel"),
});
};
@@ -1189,8 +1195,10 @@ const registerClipMenus = () => {
// saves the repository, the rest of a Xiaohongshu note saves the note, and
// the rest of a Zhihu answer or article saves that item.
// Link context is omitted because a linked image would otherwise show both
- // commands. Recreate from scratch so a previous registration cannot keep an
- // overlapping item.
+ // commands. Recreate from scratch on install/update so a previous
+ // registration cannot keep an overlapping item. Context menus persist across
+ // service worker and event page restarts; removing them at module startup can
+ // leave the browser with no menus while the background is waking up.
chrome.contextMenus.removeAll(() => {
void chrome.runtime.lastError;
createClipMenus();
@@ -1249,7 +1257,6 @@ const createClipMenus = () => {
};
chrome.runtime.onInstalled.addListener(registerClipMenus);
-registerClipMenus();
chrome.contextMenus.onClicked.addListener((info: { menuItemId?: string | number; srcUrl?: string; pageUrl?: string; frameId?: number; selectionText?: string }, tab?: { id?: number; url?: string; title?: string }) => {
if (info.menuItemId === SELECTION_MENU_ID) {
diff --git a/apps/extension/src/chrome.d.ts b/apps/extension/src/chrome.d.ts
index 14da2e6a..ad01659e 100644
--- a/apps/extension/src/chrome.d.ts
+++ b/apps/extension/src/chrome.d.ts
@@ -1 +1,5 @@
declare const chrome: any;
+
+declare module "@mixmark-io/domino" {
+ export function createDocument(html?: string, force?: boolean): Document;
+}
diff --git a/apps/extension/src/zhihu-clip.ts b/apps/extension/src/zhihu-clip.ts
index 7fb5ba04..fc07f214 100644
--- a/apps/extension/src/zhihu-clip.ts
+++ b/apps/extension/src/zhihu-clip.ts
@@ -1,3 +1,4 @@
+import { createDocument } from "@mixmark-io/domino";
import TurndownService from "turndown";
import type { ImageNoteClient } from "./image-clip";
@@ -220,13 +221,17 @@ const normalizeMarkdown = (value: string) => value.replace(/\n{3,}/g, "\n\n").tr
export const zhihuBodyFromHtml = (html: string, altFallback: string) => {
const prepared = prepareZhihuHtml(html);
+ // The extension background has no document. Give Turndown a parsed node so
+ // its browser bundle never tries to create a document in the service worker.
+ const root = createDocument(prepared.html).body;
+ if (!root) throw new Error("zhihu-dom-unavailable");
const turndown = new TurndownService({
bulletListMarker: "-",
codeBlockStyle: "fenced",
headingStyle: "atx",
linkStyle: "inlined",
});
- let markdown = normalizeMarkdown(turndown.turndown(prepared.html));
+ let markdown = normalizeMarkdown(turndown.turndown(root));
prepared.images.forEach((image, index) => {
const alt = escapeImageAlt(image.alt || altFallback);
markdown = markdown.replaceAll(`EDGEVERZHIHUIMG${index}`, `![${alt}](${image.url})`);
@@ -316,6 +321,7 @@ export const zhihuNoteTitle = (input: { title: string; author: string; body: str
};
export const zhihuNoteMarkdown = (input: {
+ kind: "answer" | "article";
author: string;
title: string;
body: string;
@@ -325,26 +331,37 @@ export const zhihuNoteMarkdown = (input: {
sourceLabel: string;
capturedAtLabel: string;
timeLabel: string;
+ questionLabel: string;
+ articleLabel: string;
+ authorLabel: string;
+ answerLabel: string;
+ articleBodyLabel: string;
}) => {
const blocks: string[] = [];
- const author = plainLine(input.author);
- if (author) blocks.push(author);
const title = plainLine(input.title);
+ const author = plainLine(input.author);
const body = input.body.trim();
- if (title && !body.startsWith(title)) blocks.push(title);
- if (body) blocks.push(body);
+ const firstLine = body.split("\n", 1)[0]?.trim();
+ const firstBreak = body.indexOf("\n");
+ const contentBody = title && firstLine === title
+ ? (firstBreak === -1 ? "" : body.slice(firstBreak + 1).trim())
+ : body;
+ if (title) blocks.push(`## ${input.kind === "answer" ? input.questionLabel : input.articleLabel}\n\n> ${title}`);
+ if (author) blocks.push(`**${input.authorLabel}** ${author}`);
+ if (contentBody) blocks.push(`## ${input.kind === "answer" ? input.answerLabel : input.articleBodyLabel}\n\n${contentBody}`);
const footer = [
input.noteUrl ? `${input.sourceLabel}: [${escapeMarkdownLabel(input.noteUrl)}](${markdownDestination(input.noteUrl)})` : "",
input.datetime ? `${input.timeLabel}: ${input.datetime}` : "",
`${input.capturedAtLabel}: ${input.capturedAt}`,
].filter(Boolean);
- blocks.push(footer.join("\n\n"));
+ blocks.push(`---\n\n${footer.join("\n\n")}`);
return blocks.join("\n\n");
};
export const saveCapturedZhihuNote = async (
client: ImageNoteClient,
input: {
+ kind: "answer" | "article";
notebookId: string;
title: string;
author: string;
@@ -357,6 +374,11 @@ export const saveCapturedZhihuNote = async (
sourceLabel: string;
capturedAtLabel: string;
timeLabel: string;
+ questionLabel: string;
+ articleLabel: string;
+ authorLabel: string;
+ answerLabel: string;
+ articleBodyLabel: string;
},
) => {
let notebookId = input.notebookId;
@@ -367,6 +389,7 @@ export const saveCapturedZhihuNote = async (
if (!notebookId) throw new Error("no-notebook");
const markdownFor = (uploaded: Array<{ url: string; resourceId: string }>) => zhihuNoteMarkdown({
+ kind: input.kind,
author: input.author,
title: input.noteTitle,
body: replaceZhihuImageUrls(input.body, uploaded),
@@ -376,6 +399,11 @@ export const saveCapturedZhihuNote = async (
sourceLabel: input.sourceLabel,
capturedAtLabel: input.capturedAtLabel,
timeLabel: input.timeLabel,
+ questionLabel: input.questionLabel,
+ articleLabel: input.articleLabel,
+ authorLabel: input.authorLabel,
+ answerLabel: input.answerLabel,
+ articleBodyLabel: input.articleBodyLabel,
});
const created = await client.createMemo({
notebookId,
diff --git a/apps/extension/zhihu-clip.test.mjs b/apps/extension/zhihu-clip.test.mjs
index e59e9a39..eabdd03b 100644
--- a/apps/extension/zhihu-clip.test.mjs
+++ b/apps/extension/zhihu-clip.test.mjs
@@ -1,4 +1,7 @@
-import { readFileSync } from "node:fs";
+import { mkdtempSync, readFileSync, rmSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { fileURLToPath, pathToFileURL } from "node:url";
import { describe, expect, test } from "bun:test";
import {
canonicalZhihuUrl,
@@ -33,6 +36,11 @@ const labels = {
sourceLabel: "来源",
capturedAtLabel: "抓取时间",
timeLabel: "时间",
+ questionLabel: "问题",
+ articleLabel: "文章",
+ authorLabel: "作者:",
+ answerLabel: "回答",
+ articleBodyLabel: "正文",
};
const located = {
@@ -73,6 +81,26 @@ describe("zhihu addresses", () => {
});
describe("zhihu note content", () => {
+ test("browser bundle converts HTML without a document in the background", async () => {
+ const outdir = mkdtempSync(join(tmpdir(), "edgeever-zhihu-worker-"));
+ try {
+ const result = await Bun.build({
+ entrypoints: [fileURLToPath(new URL("./src/zhihu-clip.ts", import.meta.url))],
+ target: "browser",
+ format: "esm",
+ outdir,
+ });
+ expect(result.success).toBe(true);
+ expect(typeof document).toBe("undefined");
+ const browserModule = await import(pathToFileURL(join(outdir, "zhihu-clip.js")).href);
+ const body = browserModule.zhihuBodyFromHtml(html, "图片");
+ expect(body.markdown).toContain("岸上没有人。潜水员听见叫声。");
+ expect(body.markdown).toContain(`![岸边](${imageUrl})`);
+ } finally {
+ rmSync(outdir, { recursive: true, force: true });
+ }
+ });
+
test("keeps the answer text, original photo, author, and canonical link", () => {
expect(zhihuTimeIso(1790739645)).toBe("2026-09-30T03:40:45.000Z");
const body = zhihuBodyFromHtml(html, "图片");
@@ -97,14 +125,15 @@ describe("zhihu note content", () => {
expect(resolved?.author).toBe("苏澄宇");
const markdown = zhihuNoteMarkdown({
...labels,
+ kind: "answer",
author: resolved.author,
title: resolved.title,
body: body.markdown,
noteUrl: resolved.noteUrl,
datetime: zhihuTimeIso(resolved.timeSeconds),
});
- expect(markdown.startsWith("苏澄宇")).toBe(true);
- expect(markdown).toContain("谁叫我上来的?");
+ expect(markdown.startsWith("## 问题\n\n> 谁叫我上来的?\n\n**作者:** 苏澄宇\n\n## 回答\n\n岸上没有人。")).toBe(true);
+ expect(markdown).toContain("\n\n---\n\n来源:");
expect(markdown).toContain(`(${answerUrl})`);
expect(markdown).toContain("时间: 2026-09-30T03:40:45.000Z");
expect(replaceZhihuImageUrls(markdown, [{ url: imageUrl, resourceId: "res 1" }])).toContain(
@@ -115,6 +144,20 @@ describe("zhihu note content", () => {
.toBe("苏澄宇: 岸上没有人。");
});
+ test("labels article title, author, and body separately", () => {
+ const markdown = zhihuNoteMarkdown({
+ ...labels,
+ kind: "article",
+ title: "专栏标题",
+ author: "页面作者",
+ body: "专栏标题\n\n文章正文。",
+ noteUrl: articleUrl,
+ datetime: "",
+ });
+ expect(markdown).toStartWith("## 文章\n\n> 专栏标题\n\n**作者:** 页面作者\n\n## 正文\n\n文章正文。");
+ expect(markdown).not.toContain("## 回答");
+ });
+
test("uses the open page when the api content is missing or shorter than a truncated copy", () => {
expect(resolveZhihuNote({ ...located, domComplete: false, domHtml: "<p>只有预览</p>" }, {
ok: false,
@@ -216,6 +259,7 @@ describe("saveCapturedZhihuNote", () => {
test("creates the note with the remote photo, then rewrites a successful upload", async () => {
const fixture = client();
const saved = await saveCapturedZhihuNote(fixture.api, {
+ kind: "answer",
notebookId: "",
title: "谁叫我上来的?",
author: "苏澄宇",
@@ -236,6 +280,7 @@ describe("saveCapturedZhihuNote", () => {
expect(fixture.calls.created.notebookId).toBe("nb_first");
expect(fixture.calls.created.tags).toEqual(["web-clip"]);
expect(fixture.calls.created.contentMarkdown).toContain(imageUrl);
+ expect(fixture.calls.created.contentMarkdown).toContain("## 回答\n\n岸上没有人。");
expect(fixture.calls.saved.contentMarkdown).toContain("![岸边](/api/v1/resources/res_1/blob)");
expect(fixture.calls.saved.contentMarkdown).not.toContain("zhimg.com");
expect(fixture.calls.saved.expectedRevision).toBe(3);
diff --git a/apps/extension/zhihu-save.html b/apps/extension/zhihu-save.html
index e28f3613..323709ea 100644
--- a/apps/extension/zhihu-save.html
+++ b/apps/extension/zhihu-save.html
@@ -3,11 +3,11 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title data-i18n="zhihuSaveWindowTitle">Save this Zhihu answer or article to EdgeEver</title>
+ <title data-i18n="zhihuSaveWindowTitle">Save Zhihu content to EdgeEver</title>
</head>
<body>
<main class="image-save-shell">
- <h1 data-i18n="zhihuSaveWindowTitle">Save this Zhihu answer or article to EdgeEver</h1>
+ <h1 data-i18n="zhihuSaveWindowTitle">Save Zhihu content to EdgeEver</h1>
<p class="hint" data-i18n="zhihuPermissionIntro">A feed lists many answers and articles. Allow access to Zhihu so the clipper can remember the one under the pointer. After that, right-click the same text once more. Only the answer or article you choose is saved to the clipper's default notebook.</p>
<div class="image-save-actions">
<button id="allow" type="button" data-i18n="allowZhihuAccess">Allow access to Zhihu</button>
diff --git a/bun.lock b/bun.lock
index 066b8f43..ef607d20 100644
--- a/bun.lock
+++ b/bun.lock
@@ -119,8 +119,9 @@
},
"apps/extension": {
"name": "@edgeever/extension",
- "version": "0.1.8",
+ "version": "0.1.13",
"dependencies": {
+ "@mixmark-io/domino": "2.2.0",
"@mozilla/readability": "^0.6.0",
"turndown": "^7.2.4",
},