feat: add autoInit switch for IIFE demo
This commit is contained in:
@@ -3,8 +3,12 @@
|
|||||||
*/
|
*/
|
||||||
import { PageAgent, type PageAgentConfig } from './PageAgent'
|
import { PageAgent, type PageAgentConfig } from './PageAgent'
|
||||||
|
|
||||||
|
const currentScript = document.currentScript as HTMLScriptElement | null
|
||||||
|
const currentScriptURL = currentScript?.src ? new URL(currentScript.src) : null
|
||||||
|
const autoInit = currentScriptURL?.searchParams.get('autoInit') !== 'false'
|
||||||
|
|
||||||
// Clean up existing instances to prevent multiple injections from bookmarklet
|
// Clean up existing instances to prevent multiple injections from bookmarklet
|
||||||
if (window.pageAgent) {
|
if (autoInit && window.pageAgent) {
|
||||||
window.pageAgent.dispose()
|
window.pageAgent.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -17,16 +21,14 @@ const DEMO_MODEL = 'qwen3.5-plus'
|
|||||||
const DEMO_BASE_URL = 'https://page-ag-testing-ohftxirgbn.cn-shanghai.fcapp.run'
|
const DEMO_BASE_URL = 'https://page-ag-testing-ohftxirgbn.cn-shanghai.fcapp.run'
|
||||||
const DEMO_API_KEY = 'NA'
|
const DEMO_API_KEY = 'NA'
|
||||||
|
|
||||||
const currentScript = document.currentScript as HTMLScriptElement | null
|
|
||||||
|
|
||||||
// in case document.x is not ready yet
|
// in case document.x is not ready yet
|
||||||
|
if (autoInit) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
let config: PageAgentConfig
|
let config: PageAgentConfig
|
||||||
let showPanel = true
|
let showPanel = true
|
||||||
|
|
||||||
if (currentScript) {
|
if (currentScriptURL) {
|
||||||
console.log('🚀 page-agent.js detected current script:', currentScript.src)
|
const url = currentScriptURL
|
||||||
const url = new URL(currentScript.src)
|
|
||||||
const model = url.searchParams.get('model') || DEMO_MODEL
|
const model = url.searchParams.get('model') || DEMO_MODEL
|
||||||
const baseURL = url.searchParams.get('baseURL') || DEMO_BASE_URL
|
const baseURL = url.searchParams.get('baseURL') || DEMO_BASE_URL
|
||||||
const apiKey = url.searchParams.get('apiKey') || DEMO_API_KEY
|
const apiKey = url.searchParams.get('apiKey') || DEMO_API_KEY
|
||||||
@@ -50,3 +52,4 @@ setTimeout(() => {
|
|||||||
|
|
||||||
console.log('🚀 page-agent.js initialized with config:', window.pageAgent.config)
|
console.log('🚀 page-agent.js initialized with config:', window.pageAgent.config)
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user