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:
@@ -91,7 +91,7 @@ npm run build:ext
|
||||
- Add a new bookmark
|
||||
|
||||
```javascript
|
||||
javascript:(function(){var s=document.createElement('script');s.src=`http://localhost:5174/page-agent.demo.js?t=${Math.random()}`;s.onload=()=>console.log(%27PageAgent ready!%27);document.head.appendChild(s);})();
|
||||
javascript:(function(){var s=document.createElement('script');s.src=`http://localhost:5174/page-agent.demo.js?lang=en-US&t=${Math.random()}`;s.onload=()=>console.log(%27PageAgent ready!%27);document.head.appendChild(s);})();
|
||||
```
|
||||
|
||||
- Click the bookmark on any page to load Page-Agent
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user