1+ // Customize widget settings
2+ const widgetSettings = {
3+ widgetId : "VD4cSN50VRpdWDIeSpVeYaQYiaND85NwIDv7ppAByDw" , // Use different widget ID for localhost - https://gurubase.io/guru/permify/integrations/web_widget
4+ overlapContent : true ,
5+ // Optional configurations:
6+ // text: "Ask AI", // Button text
7+ // margins: { bottom: "20px", right: "20px" }, // Widget positioning
8+ // lightMode: false, // Force light mode
9+ // name: "YOUR_NAME", // Widget name
10+ // iconUrl: "YOUR_ICON_URL", // Widget icon URL
11+ // bgColor: "#000000", // Widget background color
12+ } ;
13+
14+ // Load the GuruBase widget
15+ const guruScript = document . createElement ( "script" ) ;
16+ guruScript . src = "https://widget.gurubase.io/widget.latest.min.js" ;
17+ guruScript . defer = true ;
18+ guruScript . id = "guru-widget-id" ;
19+
20+ // Add widget settings as data attributes
21+ Object . entries ( widgetSettings ) . forEach ( ( [ key , value ] ) => {
22+ const dataKey = `data-${ key . replace ( / ( [ A - Z ] ) / g, '-$1' ) . toLowerCase ( ) } ` ;
23+ const dataValue = typeof value === 'object' ? JSON . stringify ( value ) : value ;
24+ guruScript . setAttribute ( dataKey , dataValue ) ;
25+ } ) ;
26+
27+ // Initialize theme handling
28+ guruScript . addEventListener ( 'load' , ( ) => {
29+ const initWidget = setInterval ( ( ) => {
30+ if ( window . chatWidget ?. switchTheme ) {
31+ clearInterval ( initWidget ) ;
32+
33+ // Handle theme changes
34+ const syncTheme = ( ) => {
35+ const isDark = document . documentElement . classList . contains ( 'dark' ) ;
36+ window . chatWidget . switchTheme ( ! isDark ) ;
37+ } ;
38+
39+ // Watch for theme changes
40+ new MutationObserver ( syncTheme ) . observe ( document . documentElement , {
41+ attributes : true ,
42+ attributeFilter : [ 'class' ]
43+ } ) ;
44+
45+ // Set initial theme
46+ syncTheme ( ) ;
47+ }
48+ } , 1000 ) ;
49+
50+ // Stop checking after 20 seconds
51+ setTimeout ( ( ) => clearInterval ( initWidget ) , 20000 ) ;
52+ } ) ;
53+ document . body . appendChild ( guruScript ) ;
0 commit comments