Skip to content

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

feat(extension): record Google image saves as the search and keyword

tianma-if8d70820d8d5a
diff --git a/apps/extension/README.md b/apps/extension/README.md
index 1345e1aa..7d9e7cf1 100644
--- a/apps/extension/README.md
+++ b/apps/extension/README.md
@@ -8,7 +8,7 @@ Chrome, Edge, and Firefox Manifest V3 extension for saving the current webpage,
- Test the connection and select a default notebook.
- Click the extension action to capture the selected content, or extract the article body with Mozilla Readability when there is no selection.
- Convert the extracted article HTML into Markdown with Turndown before uploading it.
-- Right-click an image and choose **Save image to EdgeEver**. The image file is uploaded into a new note in the default notebook, with the source page linked underneath.
+- Right-click an image and choose **Save image to EdgeEver**. The image file is uploaded into a new note in the default notebook, with the source page linked underneath. An image saved from Google Search records “Google Search” and the search keyword instead of the results URL.
- 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.
- 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.
diff --git a/apps/extension/image-clip.test.mjs b/apps/extension/image-clip.test.mjs
index e0a6dfea..17bf8e9d 100644
--- a/apps/extension/image-clip.test.mjs
+++ b/apps/extension/image-clip.test.mjs
@@ -10,7 +10,7 @@ import {
MAX_IMAGE_BYTES,
noteTitleForImage,
preferredImageUrls,
- readableClipSourceUrl,
+ googleSearchKeyword,
saveCapturedImageNote,
sniffImageMimeType,
} from "./src/image-clip.ts";
@@ -20,6 +20,8 @@ const source = {
capturedAt: "2026-09-26T00:00:00.000Z",
sourceLabel: "来源",
capturedAtLabel: "抓取时间",
+ googleSearchLabel: "Google 搜索",
+ keywordLabel: "关键词",
};
describe("preferred image URLs", () => {
@@ -108,11 +110,51 @@ describe("image bytes", () => {
});
describe("image clip sources", () => {
- test("keeps a Google image search readable and leaves other pages unchanged", () => {
- expect(readableClipSourceUrl(
+ test("records a Google image search as the search and its keyword", () => {
+ const pageUrl = "https://www.google.com/search?newwindow=1&sca_esv=080dae4805299e94&sxsrf=APpeTracking&udm=2&fbs=ABfTracking&q=cat&sa=X&ved=2ahUK&biw=1920&bih=836&dpr=2";
+ expect(googleSearchKeyword(pageUrl)).toBe("cat");
+ const markdown = imageMemoMarkdown({
+ ...source,
+ pageUrl,
+ resourceId: "res_google",
+ alt: "cat",
+ altFallback: "图片",
+ });
+ expect(markdown).toContain("来源: Google 搜索\n关键词: cat");
+ expect(markdown).not.toContain("google.com");
+ expect(markdown).not.toContain("fbs=");
+ expect(markdown).not.toContain("sxsrf=");
+ });
+
+ test("decodes the keyword and keeps an image-viewer query without the tracking URL", () => {
+ expect(googleSearchKeyword(
"https://www.google.com/search?newwindow=1&q=%E7%8C%AB&udm=2&fbs=ABfTracking&biw=1920#sv=viewer",
- )).toBe("https://www.google.com/search?q=%E7%8C%AB&udm=2");
- expect(readableClipSourceUrl("https://example.com/cats#photo")).toBe("https://example.com/cats#photo");
+ )).toBe("猫");
+ expect(googleSearchKeyword(
+ "https://www.google.com/imgres?imgurl=https%3A%2F%2Fexample.com%2Fcat.jpg&q=white+kitten&tbnid=abc",
+ )).toBe("white kitten");
+ const markdown = imageMemoMarkdown({
+ ...source,
+ pageUrl: "https://www.google.com/search?udm=2",
+ resourceId: "res_google",
+ alt: "",
+ altFallback: "图片",
+ });
+ expect(markdown).toContain("来源: Google 搜索");
+ expect(markdown).not.toContain("关键词");
+ expect(markdown).not.toContain("http");
+ expect(googleSearchKeyword("https://example.com/cats#photo")).toBeNull();
+ });
+
+ test("escapes markdown characters in the keyword", () => {
+ const markdown = imageMemoMarkdown({
+ ...source,
+ pageUrl: "https://www.google.com.hk/search?q=cat%5B1%5D*%60",
+ resourceId: "res_google",
+ alt: "",
+ altFallback: "图片",
+ });
+ expect(markdown).toContain("关键词: cat\\[1\\]\\*\\`");
});
test("reads a right-clicked data URL image", () => {
diff --git a/apps/extension/public/_locales/en/messages.json b/apps/extension/public/_locales/en/messages.json
index fc680496..22135ba4 100644
--- a/apps/extension/public/_locales/en/messages.json
+++ b/apps/extension/public/_locales/en/messages.json
@@ -159,6 +159,12 @@
"capturedAtLabel": {
"message": "Captured at"
},
+ "googleSearchLabel": {
+ "message": "Google Search"
+ },
+ "searchKeywordLabel": {
+ "message": "Keyword"
+ },
"noAvailableNotebooks": {
"message": "No notebooks are available in EdgeEver."
},
diff --git a/apps/extension/public/_locales/ja/messages.json b/apps/extension/public/_locales/ja/messages.json
index c5ea2975..b58057c7 100644
--- a/apps/extension/public/_locales/ja/messages.json
+++ b/apps/extension/public/_locales/ja/messages.json
@@ -159,6 +159,12 @@
"capturedAtLabel": {
"message": "取り込み日時"
},
+ "googleSearchLabel": {
+ "message": "Google 検索"
+ },
+ "searchKeywordLabel": {
+ "message": "キーワード"
+ },
"noAvailableNotebooks": {
"message": "EdgeEver に使えるノートブックがありません。"
},
diff --git a/apps/extension/public/_locales/zh_CN/messages.json b/apps/extension/public/_locales/zh_CN/messages.json
index 55abeb52..c101d90f 100644
--- a/apps/extension/public/_locales/zh_CN/messages.json
+++ b/apps/extension/public/_locales/zh_CN/messages.json
@@ -159,6 +159,12 @@
"capturedAtLabel": {
"message": "抓取时间"
},
+ "googleSearchLabel": {
+ "message": "Google 搜索"
+ },
+ "searchKeywordLabel": {
+ "message": "关键词"
+ },
"noAvailableNotebooks": {
"message": "EdgeEver 中没有可用的笔记本。"
},
diff --git a/apps/extension/src/background.ts b/apps/extension/src/background.ts
index 758f52e3..8e2977a4 100644
--- a/apps/extension/src/background.ts
+++ b/apps/extension/src/background.ts
@@ -253,6 +253,8 @@ const persistImage = async (
capturedAt: new Date().toISOString(),
sourceLabel: t("sourceLabel"),
capturedAtLabel: t("capturedAtLabel"),
+ googleSearchLabel: t("googleSearchLabel"),
+ keywordLabel: t("searchKeywordLabel"),
altFallback: t("imageAltFallback"),
});
} catch (error) {
diff --git a/apps/extension/src/image-clip.ts b/apps/extension/src/image-clip.ts
index 988970c0..de3887e0 100644
--- a/apps/extension/src/image-clip.ts
+++ b/apps/extension/src/image-clip.ts
@@ -194,27 +194,25 @@ export const imageAltText = (alt: string, fallback: string) => {
const escapeMarkdownLabel = (value: string) =>
value.replace(/[\r\n]+/g, " ").replace(/\\/g, "\\\\").replace(/\[/g, "\\[").replace(/\]/g, "\\]");
+const escapeMarkdownText = (value: string) =>
+ value.replace(/[\r\n]+/g, " ").replace(/[\\[\]*`]/g, (char) => `\\${char}`);
+
const markdownDestination = (value: string) =>
value.replace(/\\/g, "%5C").replace(/ /g, "%20").replace(/\(/g, "%28").replace(/\)/g, "%29");
-const GOOGLE_SEARCH_PARAMS = ["q", "udm", "tbm", "hl"] as const;
+const GOOGLE_SEARCH_PATHS = new Set(["/search", "/imgres"]);
-// Google image results put the viewer state and tracking tokens in the tab URL.
-// Keeping those turns the note source into a wall of text instead of a link back to the search.
-export const readableClipSourceUrl = (pageUrl: string) => {
+// A Google results tab URL is mostly viewer state and tracking tokens.
+// The useful part is that the image was found there, plus the search keyword.
+export const googleSearchKeyword = (pageUrl: string) => {
try {
const url = new URL(pageUrl);
const host = url.hostname.toLowerCase();
- const googleSearch = /(^|\.)google\./.test(host) && url.pathname === "/search";
- if (!googleSearch) return pageUrl;
- const next = new URL(`${url.origin}${url.pathname}`);
- for (const key of GOOGLE_SEARCH_PARAMS) {
- const value = url.searchParams.get(key);
- if (value) next.searchParams.set(key, value);
- }
- return next.toString();
+ const googleSearch = /(^|\.)google\./.test(host) && GOOGLE_SEARCH_PATHS.has(url.pathname);
+ if (!googleSearch) return null;
+ return (url.searchParams.get("q") ?? "").replace(/\s+/g, " ").trim().slice(0, 200);
} catch {
- return pageUrl;
+ return null;
}
};
@@ -229,11 +227,17 @@ export const imageSourceMarkdown = (input: {
capturedAt: string;
sourceLabel: string;
capturedAtLabel: string;
-}) => [
- `${input.sourceLabel}: [${escapeMarkdownLabel(input.pageUrl)}](${markdownDestination(input.pageUrl)})`,
- "",
- `${input.capturedAtLabel}: ${input.capturedAt}`,
-].join("\n");
+ googleSearchLabel: string;
+ keywordLabel: string;
+}) => {
+ const keyword = googleSearchKeyword(input.pageUrl);
+ const sourceLine = keyword === null
+ ? `${input.sourceLabel}: [${escapeMarkdownLabel(input.pageUrl)}](${markdownDestination(input.pageUrl)})`
+ : keyword
+ ? `${input.sourceLabel}: ${input.googleSearchLabel}\n${input.keywordLabel}: ${escapeMarkdownText(keyword)}`
+ : `${input.sourceLabel}: ${input.googleSearchLabel}`;
+ return [sourceLine, "", `${input.capturedAtLabel}: ${input.capturedAt}`].join("\n");
+};
export const imageMemoMarkdown = (input: {
resourceId: string;
@@ -243,6 +247,8 @@ export const imageMemoMarkdown = (input: {
capturedAt: string;
sourceLabel: string;
capturedAtLabel: string;
+ googleSearchLabel: string;
+ keywordLabel: string;
}) => [
`![${imageAltText(input.alt, input.altFallback)}](/api/v1/resources/${encodeURIComponent(input.resourceId)}/blob)`,
"",
@@ -298,6 +304,8 @@ export const saveCapturedImageNote = async (
capturedAt: string;
sourceLabel: string;
capturedAtLabel: string;
+ googleSearchLabel: string;
+ keywordLabel: string;
altFallback: string;
},
) => {
@@ -310,7 +318,6 @@ export const saveCapturedImageNote = async (
const contentMarkdown = imageMemoMarkdown({
...input,
- pageUrl: readableClipSourceUrl(input.pageUrl),
resourceId: "EDGEVERRESOURCEID",
});
return client.createWithImage({