chore: set the bookmark script to English locale (#580)

* chore: set the bookmark script to English locale

* chore: adapt the booklet to the locale

* refactor(demo): improve naming to better distinguish mirror and lang

---------

Co-authored-by: Simon <10131203+gaomeng1900@users.noreply.github.com>
This commit is contained in:
Erwann Robin
2026-07-03 16:49:12 +02:00
committed by GitHub
parent 4ce6d9e5c7
commit 60fe4c4c84
2 changed files with 11 additions and 5 deletions
@@ -17,11 +17,17 @@ import { useLanguage } from '../../i18n/context'
let pageAgentModule: Promise<typeof import('page-agent')> | null = null
function getInjection(useCN?: boolean) {
const cdn = useCN ? CDN_DEMO_CN_URL : CDN_DEMO_URL
/**
* Get the bookmarklet injection script
* @param cdnSource Which CDN mirror to use
* @param isZh Whether to use Chinese language
*/
function getInjection(cdnSource: 'china' | 'international', isZh?: boolean) {
const cdn = cdnSource === 'china' ? CDN_DEMO_CN_URL : CDN_DEMO_URL
const locale = isZh ? 'zh-CN' : 'en-US'
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);})();`
`javascript:(function(){var s=document.createElement('script');s.src=\`${cdn}?lang=${locale}&t=\${Math.random()}\`;s.setAttribute('crossorigin', true);s.type="text/javascript";s.onload=()=>console.log('PageAgent script loaded!');document.body.appendChild(s);})();`
)
return `
@@ -298,7 +304,7 @@ export default function HeroSection() {
</select>
<div
dangerouslySetInnerHTML={{
__html: getInjection(cdnSource === 'china'),
__html: getInjection(cdnSource, isZh),
}}
></div>
</div>