AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
feat: add EdgeEver web clipper MVP
yoma6f267bc9ac25
diff --git a/apps/extension/README.md b/apps/extension/README.mdnew file mode 100644index 00000000..499ffa94--- /dev/null+++ b/apps/extension/README.md@@ -0,0 +1,25 @@+# EdgeEver Web Clipper++Chrome/Edge Manifest V3 extension for saving the current webpage or selected text to a user's self-hosted EdgeEver instance.++## Current MVP++- Configure an EdgeEver instance URL and API Token.+- 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.+- Create a searchable EdgeEver memo with the source URL and a `web-clip` tag.++The extension does not use a central relay service. The page content is sent directly to the EdgeEver instance configured by the user.++## Development++From the repository root:++```sh+bun run build:extension+```++Then open `apps/extension/dist` from `chrome://extensions` or `edge://extensions` with Developer mode enabled and choose **Load unpacked**.++The next planned step is preserving a single-file HTML archive in R2 while keeping extracted text in the memo for search.diff --git a/apps/extension/options.html b/apps/extension/options.htmlnew file mode 100644index 00000000..7fea1dd5--- /dev/null+++ b/apps/extension/options.html@@ -0,0 +1,36 @@+<!doctype html>+<html lang="zh-CN">+ <head>+ <meta charset="UTF-8" />+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />+ <title>EdgeEver Web Clipper 设置</title>+ </head>+ <body>+ <main class="options-shell">+ <h1>EdgeEver Web Clipper</h1>+ <p class="hint">配置你自己的 EdgeEver 实例。插件不会把网页内容发送到第三方服务器。</p>+ <form id="settings-form">+ <label>+ EdgeEver 实例地址+ <input id="instance-url" type="url" placeholder="https://notes.example.com" required />+ </label>+ <label>+ API Token+ <input id="token" type="password" placeholder="从 EdgeEver 设置中创建" required />+ </label>+ <label>+ 默认笔记本+ <select id="notebook-id">+ <option value="">连接后自动使用第一个笔记本</option>+ </select>+ </label>+ <div class="actions">+ <button id="test" type="button" class="secondary">测试连接</button>+ <button id="save" type="submit">保存设置</button>+ </div>+ <p id="status" class="status" role="status"></p>+ </form>+ </main>+ <script type="module" src="/src/options.ts"></script>+ </body>+</html>diff --git a/apps/extension/package.json b/apps/extension/package.jsonnew file mode 100644index 00000000..66f36c16--- /dev/null+++ b/apps/extension/package.json@@ -0,0 +1,14 @@+{+ "name": "@edgeever/extension",+ "version": "0.1.0",+ "private": true,+ "type": "module",+ "scripts": {+ "build": "vite build --config vite.config.ts",+ "dev": "vite --config vite.config.ts"+ },+ "dependencies": {+ "@mozilla/readability": "^0.6.0",+ "turndown": "^7.2.4"+ }+}diff --git a/apps/extension/popup.html b/apps/extension/popup.htmlnew file mode 100644index 00000000..8eae4685--- /dev/null+++ b/apps/extension/popup.html@@ -0,0 +1,18 @@+<!doctype html>+<html lang="zh-CN">+ <head>+ <meta charset="UTF-8" />+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />+ <title>保存到 EdgeEver</title>+ </head>+ <body>+ <main class="popup-shell">+ <h1>EdgeEver</h1>+ <p class="hint">保存当前网页或选中内容</p>+ <button id="save" type="button">保存当前网页</button>+ <p id="status" class="status" role="status"></p>+ <button id="settings" class="link-button" type="button">打开插件设置</button>+ </main>+ <script type="module" src="/src/popup.ts"></script>+ </body>+</html>diff --git a/apps/extension/public/manifest.json b/apps/extension/public/manifest.jsonnew file mode 100644index 00000000..f63b7c66--- /dev/null+++ b/apps/extension/public/manifest.json@@ -0,0 +1,17 @@+{+ "manifest_version": 3,+ "name": "EdgeEver Web Clipper",+ "version": "0.1.0",+ "description": "Save the current webpage or selected content to your self-hosted EdgeEver instance.",+ "permissions": ["activeTab", "scripting", "storage"],+ "optional_host_permissions": ["https://*/*", "http://localhost/*", "http://127.0.0.1/*"],+ "action": {+ "default_title": "Save to EdgeEver",+ "default_popup": "popup.html"+ },+ "background": {+ "service_worker": "assets/background.js",+ "type": "module"+ },+ "options_page": "options.html"+}diff --git a/apps/extension/src/background.ts b/apps/extension/src/background.tsnew file mode 100644index 00000000..c64185fa--- /dev/null+++ b/apps/extension/src/background.ts@@ -0,0 +1,98 @@+import {+ edgeEverRequest,+ getSettings,+ listNotebooks,+ type ExtensionSettings,+} from "./extension";++type CapturedPage = {+ title: string;+ url: string;+ markdown: string;+};++const toMarkdown = (page: CapturedPage) => {+ const capturedAt = new Date().toISOString();+ return `# ${page.title.replace(/\n/g, " ")}\n\n来源:[${page.url}](${page.url})\n\n抓取时间:${capturedAt}\n\n---\n\n${page.markdown}`;+};++const createMemo = async (settings: ExtensionSettings, page: CapturedPage) => {+ const notebooks = await listNotebooks(settings);+ const notebookId = settings.notebookId || notebooks.notebooks[0]?.id;+ if (!notebookId) {+ throw new Error("EdgeEver 中没有可用的笔记本。");+ }++ await edgeEverRequest(settings, "/api/v1/memos", {+ method: "POST",+ body: JSON.stringify({+ notebookId,+ title: page.title,+ contentMarkdown: toMarkdown(page),+ tags: ["web-clip"],+ }),+ });+};++let pendingCapture: ((page: CapturedPage) => void) | null = null;++chrome.runtime.onMessage.addListener((message: { type?: string; page?: CapturedPage }, _sender: unknown, sendResponse: (response: unknown) => void) => {+ if (message.type === "capturedPage" && message.page) {+ pendingCapture?.(message.page);+ pendingCapture = null;+ return false;+ }++ if (message.type === "testConnection") {+ void (async () => {+ try {+ const settings = await getSettings();+ const notebooks = await listNotebooks(settings);+ sendResponse({ ok: true, notebooks: notebooks.notebooks });+ } catch (error) {+ sendResponse({ ok: false, message: error instanceof Error ? error.message : "连接失败。" });+ }+ })();+ return true;+ }++ if (message.type === "captureCurrentPage") {+ void (async () => {+ try {+ const settings = await getSettings();+ const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });+ if (!tab?.id) {+ throw new Error("找不到当前页面。");+ }++ const page = await new Promise<CapturedPage>((resolve, reject) => {+ const timeout = setTimeout(() => {+ pendingCapture = null;+ reject(new Error("网页内容提取超时,请重试。"));+ }, 15_000);++ pendingCapture = (capturedPage) => {+ clearTimeout(timeout);+ resolve(capturedPage);+ };++ void chrome.scripting.executeScript({+ target: { tabId: tab.id },+ files: ["assets/capture.js"],+ }).catch((error: unknown) => {+ clearTimeout(timeout);+ pendingCapture = null;+ reject(error);+ });+ });+ await createMemo(settings, page);+ sendResponse({ ok: true });+ } catch (error) {+ sendResponse({ ok: false, message: error instanceof Error ? error.message : "保存失败。" });+ }+ })();+ return true;+ }++ return false;+});diff --git a/apps/extension/src/capture.ts b/apps/extension/src/capture.tsnew file mode 100644index 00000000..d11cc64c--- /dev/null+++ b/apps/extension/src/capture.ts@@ -0,0 +1,50 @@+import { Readability } from "@mozilla/readability";+import TurndownService from "turndown";++type CapturedPage = {+ title: string;+ url: string;+ markdown: string;+};++const getSelectionHtml = () => {+ const selection = window.getSelection();+ if (!selection || selection.rangeCount === 0 || !selection.toString().trim()) {+ return "";+ }++ const container = document.createElement("div");+ for (let index = 0; index < selection.rangeCount; index += 1) {+ container.appendChild(selection.getRangeAt(index).cloneContents());+ }++ return container.innerHTML.trim();+};++const normalizeMarkdown = (value: string) => value.replace(/\n{3,}/g, "\n\n").trim();++const capturePage = (): CapturedPage => {+ const selectionHtml = getSelectionHtml();+ const documentClone = document.cloneNode(true) as Document;+ const article = new Readability(documentClone, {+ charThreshold: 80,+ keepClasses: false,+ }).parse();+ const sourceHtml = selectionHtml || article?.content || document.body?.innerHTML || "";+ const title = article?.title?.trim() || document.title.trim() || location.hostname;+ const turndown = new TurndownService({+ bulletListMarker: "-",+ codeBlockStyle: "fenced",+ headingStyle: "atx",+ linkStyle: "inlined",+ });+ const markdown = normalizeMarkdown(turndown.turndown(sourceHtml));++ return {+ title,+ url: location.href,+ markdown: markdown || "(网页没有可提取的正文内容)",+ };+};++void chrome.runtime.sendMessage({ type: "capturedPage", page: capturePage() });diff --git a/apps/extension/src/chrome.d.ts b/apps/extension/src/chrome.d.tsnew file mode 100644index 00000000..14da2e6a--- /dev/null+++ b/apps/extension/src/chrome.d.ts@@ -0,0 +1 @@+declare const chrome: any;diff --git a/apps/extension/src/extension.ts b/apps/extension/src/extension.tsnew file mode 100644index 00000000..4ffc5077--- /dev/null+++ b/apps/extension/src/extension.ts@@ -0,0 +1,84 @@+export type ExtensionSettings = {+ instanceUrl: string;+ token: string;+ notebookId: string;+};++export type Notebook = {+ id: string;+ name: string;+};++export const DEFAULT_SETTINGS: ExtensionSettings = {+ instanceUrl: "",+ token: "",+ notebookId: "",+};++export const getSettings = async (): Promise<ExtensionSettings> => {+ const stored = await chrome.storage.local.get(DEFAULT_SETTINGS);+ return {+ instanceUrl: typeof stored.instanceUrl === "string" ? stored.instanceUrl : "",+ token: typeof stored.token === "string" ? stored.token : "",+ notebookId: typeof stored.notebookId === "string" ? stored.notebookId : "",+ };+};++export const saveSettings = async (settings: ExtensionSettings) => {+ await chrome.storage.local.set(settings);+};++export const normalizeInstanceUrl = (value: string) => {+ const trimmed = value.trim();+ if (!trimmed) {+ return "";+ }++ const withProtocol = /^https?:\/\//i.test(trimmed) ? trimmed : `https://${trimmed}`;+ return withProtocol.replace(/\/+$/, "");+};++export const getInstanceOrigin = (instanceUrl: string) => {+ const url = new URL(normalizeInstanceUrl(instanceUrl));+ return url.origin;+};++export const requestInstancePermission = async (instanceUrl: string) => {+ const origin = getInstanceOrigin(instanceUrl);+ const granted = await chrome.permissions.request({ origins: [`${origin}/*`] });+ if (!granted) {+ throw new Error("需要允许插件访问你的 EdgeEver 实例。");+ }+};++export const edgeEverRequest = async <T>(settings: ExtensionSettings, path: string, init?: RequestInit): Promise<T> => {+ const instanceUrl = normalizeInstanceUrl(settings.instanceUrl);+ if (!instanceUrl || !settings.token) {+ throw new Error("请先在插件设置中填写 EdgeEver 地址和 API Token。");+ }++ const response = await fetch(`${instanceUrl}${path}`, {+ ...init,+ headers: {+ Authorization: `Bearer ${settings.token}`,+ "Content-Type": "application/json",+ ...init?.headers,+ },+ });++ if (!response.ok) {+ const body = await response.json().catch(() => null) as { error?: { message?: string } } | null;+ throw new Error(body?.error?.message || `EdgeEver 请求失败(${response.status})。`);+ }++ return response.json() as Promise<T>;+};++export const listNotebooks = (settings: ExtensionSettings) =>+ edgeEverRequest<{ notebooks: Notebook[] }>(settings, "/api/v1/notebooks");++export const testConnection = async (settings: ExtensionSettings) => {+ await requestInstancePermission(settings.instanceUrl);+ const result = await listNotebooks(settings);+ return result.notebooks;+};diff --git a/apps/extension/src/options.ts b/apps/extension/src/options.tsnew file mode 100644index 00000000..0206e6d6--- /dev/null+++ b/apps/extension/src/options.ts@@ -0,0 +1,74 @@+import "./styles.css";+import { getSettings, saveSettings, testConnection, type ExtensionSettings } from "./extension";++type NotebookSelect = {+ value: string;+ replaceChildren: (...nodes: Node[]) => void;+ add: (option: HTMLOptionElement) => void;+};++const form = document.querySelector<HTMLFormElement>("#settings-form");+const instanceUrlInput = document.querySelector<HTMLInputElement>("#instance-url");+const tokenInput = document.querySelector<HTMLInputElement>("#token");+const notebookSelect = document.querySelector("#notebook-id") as NotebookSelect | null;+const testButton = document.querySelector<HTMLButtonElement>("#test");+const status = document.querySelector<HTMLParagraphElement>("#status");++const setStatus = (message: string, kind: "normal" | "error" | "success" = "normal") => {+ if (status) {+ status.textContent = message;+ status.dataset.kind = kind;+ }+};++const readSettings = (): ExtensionSettings => ({+ instanceUrl: instanceUrlInput?.value.trim() ?? "",+ token: tokenInput?.value.trim() ?? "",+ notebookId: notebookSelect?.value ?? "",+});++const renderNotebooks = (notebooks: Array<{ id: string; name: string }>, selectedId: string) => {+ if (!notebookSelect) {+ return;+ }++ notebookSelect.replaceChildren(new Option("连接后自动使用第一个笔记本", ""));+ for (const notebook of notebooks) {+ notebookSelect.add(new Option(notebook.name, notebook.id));+ }+ notebookSelect.value = selectedId;+};++const initialize = async () => {+ const settings = await getSettings();+ if (instanceUrlInput) instanceUrlInput.value = settings.instanceUrl;+ if (tokenInput) tokenInput.value = settings.token;+ if (notebookSelect) notebookSelect.value = settings.notebookId;+};++testButton?.addEventListener("click", async () => {+ testButton.disabled = true;+ setStatus("正在连接……");+ try {+ const settings = readSettings();+ const notebooks = await testConnection(settings);+ renderNotebooks(notebooks, notebookSelect?.value ?? "");+ setStatus(`连接成功,共 ${notebooks.length} 个笔记本。`, "success");+ } catch (error) {+ setStatus(error instanceof Error ? error.message : "连接失败。", "error");+ } finally {+ testButton.disabled = false;+ }+});++form?.addEventListener("submit", async (event) => {+ event.preventDefault();+ try {+ await saveSettings(readSettings());+ setStatus("设置已保存。", "success");+ } catch (error) {+ setStatus(error instanceof Error ? error.message : "保存失败。", "error");+ }+});++void initialize();diff --git a/apps/extension/src/popup.ts b/apps/extension/src/popup.tsnew file mode 100644index 00000000..1d34a299--- /dev/null+++ b/apps/extension/src/popup.ts@@ -0,0 +1,41 @@+import "./styles.css";+import { getSettings, requestInstancePermission } from "./extension";++const saveButton = document.querySelector<HTMLButtonElement>("#save");+const settingsButton = document.querySelector<HTMLButtonElement>("#settings");+const status = document.querySelector<HTMLParagraphElement>("#status");++const setStatus = (message: string, kind: "normal" | "error" | "success" = "normal") => {+ if (status) {+ status.textContent = message;+ status.dataset.kind = kind;+ }+};++saveButton?.addEventListener("click", async () => {+ saveButton.disabled = true;+ setStatus("正在读取网页并保存……");++ try {+ const settings = await getSettings();+ if (!settings.instanceUrl || !settings.token) {+ throw new Error("请先打开插件设置。");+ }++ await requestInstancePermission(settings.instanceUrl);+ const response = await chrome.runtime.sendMessage({ type: "captureCurrentPage" });+ if (!response?.ok) {+ throw new Error(response?.message || "保存失败。");+ }++ setStatus("已保存到 EdgeEver。", "success");+ } catch (error) {+ setStatus(error instanceof Error ? error.message : "保存失败。", "error");+ } finally {+ saveButton.disabled = false;+ }+});++settingsButton?.addEventListener("click", () => {+ void chrome.runtime.openOptionsPage();+});diff --git a/apps/extension/src/styles.css b/apps/extension/src/styles.cssnew file mode 100644index 00000000..84cc4dd7--- /dev/null+++ b/apps/extension/src/styles.css@@ -0,0 +1,118 @@+:root {+ color: #172033;+ background: #f8fafc;+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;+}++body {+ margin: 0;+ min-width: 320px;+}++.popup-shell,+.options-shell {+ box-sizing: border-box;+ margin: 0 auto;+ padding: 24px;+}++.popup-shell {+ width: 320px;+}++.options-shell {+ max-width: 640px;+}++h1 {+ margin: 0 0 8px;+ font-size: 22px;+}++.hint {+ margin: 0 0 20px;+ color: #64748b;+ font-size: 13px;+ line-height: 1.6;+}++label {+ display: grid;+ gap: 8px;+ margin: 16px 0;+ font-size: 14px;+ font-weight: 600;+}++input,+select,+button {+ box-sizing: border-box;+ border-radius: 8px;+ font: inherit;+}++input,+select {+ width: 100%;+ border: 1px solid #cbd5e1;+ background: white;+ padding: 10px 12px;+}++button {+ border: 0;+ background: #0f766e;+ color: white;+ cursor: pointer;+ padding: 10px 14px;+ font-weight: 600;+}++button:hover {+ background: #115e59;+}++button:disabled {+ cursor: wait;+ opacity: 0.6;+}++.secondary,+.link-button {+ background: transparent;+ color: #0f766e;+}++.secondary:hover,+.link-button:hover {+ background: #ccfbf1;+}++.link-button {+ margin-top: 8px;+ padding-inline: 0;+}++.actions {+ display: flex;+ justify-content: flex-end;+ gap: 8px;+ margin-top: 22px;+}++.status {+ min-height: 20px;+ margin: 14px 0 0;+ color: #475569;+ font-size: 13px;+ line-height: 1.5;+}++.status[data-kind="error"] {+ color: #b91c1c;+}++.status[data-kind="success"] {+ color: #047857;+}diff --git a/apps/extension/tsconfig.json b/apps/extension/tsconfig.jsonnew file mode 100644index 00000000..c6e88ae4--- /dev/null+++ b/apps/extension/tsconfig.json@@ -0,0 +1,7 @@+{+ "extends": "../../tsconfig.json",+ "compilerOptions": {+ "types": ["node", "vite/client"]+ },+ "include": ["src", "vite.config.ts"]+}diff --git a/apps/extension/vite.config.ts b/apps/extension/vite.config.tsnew file mode 100644index 00000000..35f0ab90--- /dev/null+++ b/apps/extension/vite.config.ts@@ -0,0 +1,23 @@+import { fileURLToPath, URL } from "node:url";+import { defineConfig } from "vite";++export default defineConfig({+ root: "apps/extension",+ build: {+ outDir: "dist",+ emptyOutDir: true,+ rollupOptions: {+ input: {+ popup: fileURLToPath(new URL("./popup.html", import.meta.url)),+ options: fileURLToPath(new URL("./options.html", import.meta.url)),+ background: fileURLToPath(new URL("./src/background.ts", import.meta.url)),+ capture: fileURLToPath(new URL("./src/capture.ts", import.meta.url)),+ },+ output: {+ entryFileNames: "assets/[name].js",+ chunkFileNames: "assets/[name]-[hash].js",+ assetFileNames: "assets/[name]-[hash][extname]",+ },+ },+ },+});diff --git a/bun.lock b/bun.lockindex 97f2fab8..5aa01df2 100644--- a/bun.lock+++ b/bun.lock@@ -67,6 +67,14 @@"name": "@edgeever/api","version": "0.1.3",},+ "apps/extension": {+ "name": "@edgeever/extension",+ "version": "0.1.0",+ "dependencies": {+ "@mozilla/readability": "^0.6.0",+ "turndown": "^7.2.4",+ },+ },"apps/mobile": {"name": "@edgeever/mobile","version": "0.1.3",@@ -437,6 +445,8 @@"@edgeever/client": ["@edgeever/client@workspace:packages/client"],+ "@edgeever/extension": ["@edgeever/extension@workspace:apps/extension"],+"@edgeever/mobile": ["@edgeever/mobile@workspace:apps/mobile"],"@edgeever/shared": ["@edgeever/shared@workspace:packages/shared"],@@ -707,6 +717,8 @@"@mixmark-io/domino": ["@mixmark-io/[email protected]", "", {}, "sha512-Y28PR25bHXUg88kCV7nivXrP2Nj2RueZ3/l/jdx6J9f8J4nsEGcgX0Qe6lt7Pa+J79+kPiJU3LguR6O/6zrLOw=="],+ "@mozilla/readability": ["@mozilla/[email protected]", "", {}, "sha512-juG5VWh4qAivzTAeMzvY9xs9HY5rAcr2E4I7tiSSCokRFi7XIZCAu92ZkSTsIj1OPceCifL3cpfteP3pDT9/QQ=="],+"@napi-rs/wasm-runtime": ["@napi-rs/[email protected]", "", { "dependencies": { "@tybys/wasm-util": "^0.10.3" }, "peerDependencies": { "@emnapi/core": "^1.7.1", "@emnapi/runtime": "^1.7.1" } }, "sha512-ZLv/JdUfkvOy9eCnnBaGfiO+XimbjebAeO+MRQqD/B+FR1tnRN0tpKSJHRbE8sFfS6aqsXZ67TQjfwfsxULVbg=="],"@nodable/entities": ["@nodable/[email protected]", "", {}, "sha512-9uGyhaQavEUMC8AIddIjau4NsnsXhou+j5sBAGojCM1oxmQpVKTWR/9JxABD6UAv12vpIms55fPZKFQEhG6uBg=="],diff --git a/package.json b/package.jsonindex 6367535f..4f5fee01 100644--- a/package.json+++ b/package.json@@ -16,6 +16,8 @@"dev:mobile": "bun --cwd apps/mobile expo start","dev:site": "bun --cwd apps/site dev","build": "bun run build:web",+ "build:extension": "vite build --config apps/extension/vite.config.ts",+ "dev:extension": "vite --config apps/extension/vite.config.ts","build:web": "vite build --config apps/web/vite.config.ts","build:site": "bun --cwd apps/site build","preview:web": "vite preview --config apps/web/vite.config.ts --host 127.0.0.1 --port 4173",