1+ ( function ( ) {
12const guideHtml = `
23<div class="maxkb-mask">
34 <div class="maxkb-content"></div>
@@ -23,7 +24,7 @@ const chatButtonHtml=
2324<img style="height:100%;width:100%;" src="{{float_icon}}">
2425</div>`
2526
26-
27+
2728
2829const getChatContainerHtml = ( protocol , host , token , query ) => {
2930 return `<div id="maxkb-chat-container">
@@ -43,7 +44,7 @@ const getChatContainerHtml=(protocol,host,token,query)=>{
4344}
4445/**
4546 * 初始化引导
46- * @param {* } root
47+ * @param {* } root
4748 */
4849const initGuide = ( root ) => {
4950 root . insertAdjacentHTML ( "beforeend" , guideHtml )
@@ -131,8 +132,9 @@ const initChat=(root)=>{
131132function initMaxkb ( ) {
132133 const maxkb = document . createElement ( 'div' )
133134 const root = document . createElement ( 'div' )
134- root . id = "maxkb"
135- initMaxkbStyle ( maxkb )
135+ const maxkbId = 'maxkb-' + crypto . randomUUID ( ) . split ( '-' ) [ 0 ]
136+ root . id = maxkbId
137+ initMaxkbStyle ( maxkb , maxkbId )
136138 maxkb . appendChild ( root )
137139 document . body . appendChild ( maxkb )
138140 const maxkbMaskTip = localStorage . getItem ( 'maxkbMaskTip' )
@@ -142,9 +144,9 @@ function initMaxkb(){
142144 initChat ( root )
143145}
144146
145-
147+
146148// 初始化全局样式
147- function initMaxkbStyle ( root ) {
149+ function initMaxkbStyle ( root , maxkbId ) {
148150 style = document . createElement ( 'style' )
149151 style . type = 'text/css'
150152 style . innerText = `
@@ -306,6 +308,7 @@ function initMaxkbStyle(root){
306308 height: 600px;
307309 }
308310 }`
311+ . replaceAll ( '#maxkb ' , `#${ maxkbId } ` )
309312 root . appendChild ( style )
310313}
311314
@@ -319,3 +322,4 @@ function embedChatbot() {
319322 } else console . error ( 'invalid parameter' )
320323}
321324window . addEventListener ( 'load' , embedChatbot )
325+ } ) ( ) ;
0 commit comments