From aa694e3b855a7d6adeaafcacefa08dd324dbf9cb Mon Sep 17 00:00:00 2001 From: Simon <10131203+gaomeng1900@users.noreply.github.com> Date: Tue, 16 Dec 2025 20:17:58 +0800 Subject: [PATCH] docs: stable CDN --- packages/website/src/constants.ts | 3 + .../src/docs/integration/cdn-setup/page.tsx | 12 +++- .../docs/introduction/quick-start/page.tsx | 6 +- .../website/src/i18n/locales/en-US/home.ts | 3 + .../website/src/i18n/locales/zh-CN/home.ts | 3 + packages/website/src/page.tsx | 56 +++++++++++++------ 6 files changed, 60 insertions(+), 23 deletions(-) create mode 100644 packages/website/src/constants.ts diff --git a/packages/website/src/constants.ts b/packages/website/src/constants.ts new file mode 100644 index 0000000..5742d7a --- /dev/null +++ b/packages/website/src/constants.ts @@ -0,0 +1,3 @@ +export const CDN_URL = 'https://cdn.jsdelivr.net/npm/page-agent@latest/dist/umd/page-agent.js' +export const CDN_CN_URL = + 'https://registry.npmmirror.com/page-agent/latest/files/dist/umd/page-agent.js' diff --git a/packages/website/src/docs/integration/cdn-setup/page.tsx b/packages/website/src/docs/integration/cdn-setup/page.tsx index 5701c8f..eb411d0 100644 --- a/packages/website/src/docs/integration/cdn-setup/page.tsx +++ b/packages/website/src/docs/integration/cdn-setup/page.tsx @@ -1,5 +1,6 @@ import BetaNotice from '@/components/BetaNotice' import CodeEditor from '@/components/CodeEditor' +import { CDN_CN_URL, CDN_URL } from '@/constants' export default function CdnSetup() { return ( @@ -15,11 +16,16 @@ export default function CdnSetup() { +// CDN: \t${CDN_URL} +// Mirror: \t${CDN_CN_URL} + `} /> diff --git a/packages/website/src/docs/introduction/quick-start/page.tsx b/packages/website/src/docs/introduction/quick-start/page.tsx index b26d8a7..a2140c9 100644 --- a/packages/website/src/docs/introduction/quick-start/page.tsx +++ b/packages/website/src/docs/introduction/quick-start/page.tsx @@ -2,6 +2,7 @@ import { useTranslation } from 'react-i18next' import BetaNotice from '@/components/BetaNotice' import CodeEditor from '@/components/CodeEditor' +import { CDN_CN_URL, CDN_URL } from '@/constants' export default function QuickStart() { const { t } = useTranslation('docs') @@ -23,8 +24,9 @@ export default function QuickStart() {

{t('quick_start.step1_cdn')}

`} + code={`// CDN: \t${CDN_URL} +// Mirror: \t${CDN_CN_URL} +`} language="html" />
diff --git a/packages/website/src/i18n/locales/en-US/home.ts b/packages/website/src/i18n/locales/en-US/home.ts index 4d9f084..3a89aeb 100644 --- a/packages/website/src/i18n/locales/en-US/home.ts +++ b/packages/website/src/i18n/locales/en-US/home.ts @@ -18,6 +18,9 @@ export default { step1_content: 'Show your bookmarks bar', step2_title: 'Step 2:', step2_content: 'Drag this button to your bookmarks', + cdn_label: 'CDN Source', + cdn_international: 'International', + cdn_china: 'China Mirror', step3_title: 'Step 3:', step3_content: 'Click the bookmark on any site to activate', notice_title: '⚠️ Heads Up', diff --git a/packages/website/src/i18n/locales/zh-CN/home.ts b/packages/website/src/i18n/locales/zh-CN/home.ts index 7bd075c..a94cc5a 100644 --- a/packages/website/src/i18n/locales/zh-CN/home.ts +++ b/packages/website/src/i18n/locales/zh-CN/home.ts @@ -17,6 +17,9 @@ export default { step1_content: '显示收藏夹栏', step2_title: '步骤 2:', step2_content: '拖拽下面按钮到收藏夹栏', + cdn_label: 'CDN 源', + cdn_international: '国际', + cdn_china: '国内镜像', step3_title: '步骤 3:', step3_content: '在其他网站点击收藏夹中的按钮即可使用', notice_title: '⚠️ 注意', diff --git a/packages/website/src/page.tsx b/packages/website/src/page.tsx index 7389c47..b232129 100644 --- a/packages/website/src/page.tsx +++ b/packages/website/src/page.tsx @@ -6,23 +6,27 @@ import { Link, useSearchParams } from 'wouter' import Footer from './components/Footer' import Header from './components/Header' +import { CDN_CN_URL, CDN_URL } from './constants' -const injection = encodeURI( - "javascript:(function(){var s=document.createElement('script');s.src=`https://hwcxiuzfylggtcktqgij.supabase.co/storage/v1/object/public/demo-public/v0.0.4/page-agent.js?t=${Math.random()}`;s.setAttribute('crossorigin', true);s.type=`text/javascript`;s.onload=()=>console.log('PageAgent script loaded!');document.body.appendChild(s);})();" -) +function getInjection(useCN?: boolean) { + const cdn = useCN ? CDN_CN_URL : CDN_URL -const injectionA = ` - - ✨PageAgent - + const injection = encodeURI( + `javascript:(function(){var s=document.createElement('script');s.src=\`${cdn}?t=\${Math.random()}\`;s.setAttribute('crossorigin', true);s.type="text/javascript";s.onload=()=>console.log('PageAgent script loaded!');document.body.appendChild(s);})();` + ) -` + return ` + + ✨PageAgent + + ` +} export default function HomePage() { const { t, i18n } = useTranslation(['home', 'common']) @@ -38,6 +42,7 @@ export default function HomePage() { const isOther = params.has('try_other') const [activeTab, setActiveTab] = useState<'try' | 'other'>(isOther ? 'other' : 'try') + const [cdnSource, setCdnSource] = useState<'international' | 'china'>('international') const handleExecute = async () => { if (!task.trim()) return @@ -194,10 +199,25 @@ export default function HomePage() { {' '} {t('home:try_other.step2_content')}

-
+
+ +
+
{/* Usage Instructions */}