22 * ai-init.js - AI page initialization and visitor tracking
33 */
44
5- // Load and auto-refresh visitor count for demo page
6- document . addEventListener ( 'DOMContentLoaded' , function ( ) {
5+ ( function ( ) {
6+ // Load and auto-refresh visitor count for demo page
77 var countElement = document . getElementById ( 'visitorCount' ) ;
88 if ( ! countElement || typeof VisitorTracking === 'undefined' ) {
99 return ;
@@ -12,9 +12,8 @@ document.addEventListener('DOMContentLoaded', function() {
1212 var currentCount = null ;
1313
1414 // Function to fetch and update visitor count
15- async function updateVisitorCount ( ) {
16- try {
17- var count = await VisitorTracking . getVisitorCount ( 'demo' ) ;
15+ function updateVisitorCount ( ) {
16+ VisitorTracking . getVisitorCount ( 'demo' ) . then ( function ( count ) {
1817 if ( count !== null ) {
1918 // Only update if count has changed or is first load
2019 if ( currentCount !== count ) {
@@ -28,13 +27,13 @@ document.addEventListener('DOMContentLoaded', function() {
2827 currentCount = '0' ;
2928 }
3029 }
31- } catch ( error ) {
30+ } ) . catch ( function ( error ) {
3231 console . error ( 'Failed to load visitor count:' , error ) ;
3332 if ( currentCount === null ) {
3433 countElement . textContent = '0' ;
3534 currentCount = '0' ;
3635 }
37- }
36+ } ) ;
3837 }
3938
4039 // Initial load
@@ -43,4 +42,4 @@ document.addEventListener('DOMContentLoaded', function() {
4342 // Auto-refresh every 5 minutes (300,000 ms)
4443 setInterval ( updateVisitorCount , 300000 ) ;
4544 console . log ( 'Visitor count auto-refresh enabled (every 5 minutes)' ) ;
46- } ) ;
45+ } ) ( ) ;
0 commit comments