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
import { readFile } from 'node:fs/promises';
const root=import.meta.dir + '/../../../../apps/extension';
const messages=JSON.parse(await readFile(root+'/public/_locales/zh_CN/messages.json','utf8'));
const saved=[];let failNext=false;
const bridge=`const labels=${JSON.stringify(messages)}; window.chrome={i18n:{getMessage:(k)=>k==='@@ui_locale'?'zh_CN':(labels[k]?.message||k),getUILanguage:()=> 'zh-CN'},storage:{local:{get:async()=>({instanceUrl:'https://fixture.test',token:'fixture-only',notebookId:''})}},permissions:{request:async()=>true},runtime:{openOptionsPage:async()=>{},sendMessage:async(m)=>{if(m.type==='getCurrentPageCaptureMode')return {kind:'page'};if(m.type==='startRegionClip'){const s=document.createElement('script');s.src='/assets/region-clip.js?'+Date.now();await new Promise((res,rej)=>{s.onload=res;s.onerror=rej;document.head.append(s)});return {ok:true}}if(m.type==='saveRegionClip')return fetch('/captures',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify(m)}).then(r=>r.json());throw Error('Unexpected message '+m.type)}}};`;
const fixture=`<!doctype html><html lang="zh-CN"><meta charset="UTF-8"><title>区域剪藏验收文章</title><style>body{margin:0;background:#f5f5f3;color:#222;font:16px/1.8 system-ui}header{padding:22px 6vw;background:white;border-bottom:1px solid #ddd}main{max-width:1040px;margin:50px auto;display:grid;grid-template-columns:1fr 240px;gap:50px}article{background:white;padding:40px;border-radius:12px}h1{font-size:32px;line-height:1.3}h2{font-size:22px}aside{font-size:14px;color:#777}a{color:#244c36}img{width:280px;height:100px}.secret{display:none}pre{padding:16px;background:#f5f5f5}table{border-collapse:collapse}td,th{border:1px solid #ddd;padding:8px 20px}iframe{position:fixed;right:14px;top:14px;width:320px;height:330px;border:1px solid #ddd;border-radius:12px;z-index:100;background:#fff}#lower{margin-top:500px;padding:50px}button{padding:10px}</style><header><strong>Field Notes</strong> · 网页区域剪藏测试 <button id="open-popup" onclick="document.querySelector('iframe').hidden=false">打开插件</button><button id="restart" onclick="chrome.runtime.sendMessage({type:'startRegionClip'})">再次选择</button></header><main><article id="article"><h1>把需要的内容留下</h1><p id="intro">这段导语不属于目标区域。</p><section id="chosen"><h2 id="heading">只剪藏这一节</h2><p id="paragraph">保留这段文字和 <a id="source-link" href="/should-not-navigate" onclick="window.linkClicks=(window.linkClicks||0)+1">原文链接</a>。</p><table><tr><th>项目</th><th>结果</th></tr><tr><td>区域内容</td><td>完整保留</td></tr></table><pre><code>const first = 1;\n\nconst second = 2;</code></pre><img src="/photo.svg" alt="所选图片"><p class="secret">CSS 隐藏的私密内容</p><p hidden>hidden 私密内容</p><input value="表单私密值"></section><section id="sibling"><h2>下一节</h2><p>这是相邻区域,用方向键切换。</p></section></article><aside>广告和推荐内容<br>这一栏不应该进入笔记。</aside></main><section id="lower"><h2>页面底部</h2><p>用于滚动位置与边界验证。</p></section><iframe src="/popup.html" hidden></iframe><script>${bridge}</script></html>`;
Bun.serve({port:18703,hostname:'127.0.0.1',async fetch(req){const u=new URL(req.url);if(u.pathname==='/')return new Response(fixture,{headers:{'content-type':'text/html;charset=utf-8'}});if(u.pathname==='/photo.svg')return new Response('<svg xmlns="http://www.w3.org/2000/svg" width="280" height="100"><rect width="280" height="100" fill="#dae4d8"/><text x="20" y="60" fill="#07130b">Selected image</text></svg>',{headers:{'content-type':'image/svg+xml'}});if(u.pathname==='/fail-next'){failNext=true;return Response.json({ok:true})}if(u.pathname==='/captures'){if(req.method==='POST'){const value=await req.json();if(failNext){failNext=false;return Response.json({ok:false,message:'测试保存失败,请稍后重试'})}saved.push(value);return Response.json({ok:true,message:'已保存'})}return Response.json(saved)}if(u.pathname==='/popup.html'){let html=await readFile(root+'/dist/popup.html','utf8');html=html.replace('<head>',`<head><script>window.chrome=parent.chrome;window.close=()=>parent.document.querySelector('iframe').hidden=true;</script>`);return new Response(html,{headers:{'content-type':'text/html;charset=utf-8'}})}try{const file=await readFile(root+'/dist'+u.pathname);const type=u.pathname.endsWith('.js')?'text/javascript':u.pathname.endsWith('.css')?'text/css':u.pathname.endsWith('.png')?'image/png':'text/plain';return new Response(file,{headers:{'content-type':type}})}catch{return new Response('Not found',{status:404})}}});
console.log('Region UI fixture http://127.0.0.1:18703');