2025-09-29 16:33:15 +08:00
|
|
|
/**
|
|
|
|
|
* Auto-run entry for page-agent.js. Insert this script into your page to get page-agent functionality.
|
|
|
|
|
*/
|
|
|
|
|
import { PageAgent, type PageAgentConfig } from './PageAgent'
|
|
|
|
|
|
|
|
|
|
// Clean up existing instances to prevent multiple injections from bookmarklet
|
|
|
|
|
if (window.pageAgent) {
|
|
|
|
|
window.pageAgent.dispose()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mount to global window object
|
|
|
|
|
window.PageAgent = PageAgent
|
|
|
|
|
|
|
|
|
|
// Export for ES module usage
|
|
|
|
|
export { PageAgent }
|
|
|
|
|
|
|
|
|
|
console.log('🚀 page-agent.js loaded!')
|
|
|
|
|
|
|
|
|
|
const currentScript = document.currentScript as HTMLScriptElement | null
|
|
|
|
|
if (currentScript) {
|
|
|
|
|
const url = new URL(currentScript.src)
|
2025-10-21 15:13:16 +08:00
|
|
|
const model = url.searchParams.get('model')
|
2025-09-29 16:33:15 +08:00
|
|
|
const language = (url.searchParams.get('lang') as 'zh-CN' | 'en-US') || 'zh-CN'
|
2025-10-21 15:13:16 +08:00
|
|
|
const config = { model, language } as PageAgentConfig
|
2025-09-29 16:33:15 +08:00
|
|
|
window.pageAgent = new PageAgent(config)
|
|
|
|
|
} else {
|
|
|
|
|
window.pageAgent = new PageAgent()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('🚀 page-agent.js initialized with config:', window.pageAgent.config)
|
|
|
|
|
|
|
|
|
|
window.pageAgent.bus.emit('panel:show') // Show panel
|