MediaWiki:Common.js: Difference between revisions

From Helix Project Wiki
No edit summary
No edit summary
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
// Helix Project AI Assistant - Enhanced Chatbase Integration
// Helix Project AI Assistant - Chatbase with Fallback Bubble
window.addEventListener('load', function() {
window.addEventListener('load', function() {
     console.log('Loading Helix AI Assistant...');
     console.log('Loading Helix AI Assistant for Wiki...');
      
      
     // Remove any existing Chatbase elements first
     // Add the chat bubble to wiki pages
     const existingChatbase = document.querySelector('[chatbotid="i65eBj3COxUlFEU_Lsrw0"]');
     addChatBubbleToWiki();
    if (existingChatbase) {
        existingChatbase.remove();
    }
      
      
    // Your existing Chatbase integration
     var script = document.createElement('script');
     var script = document.createElement('script');
     script.src = 'https://www.chatbase.co/embed.min.js';
     script.src = 'https://www.chatbase.co/embed.min.js';
Line 17: Line 15:
      
      
     script.onload = function() {
     script.onload = function() {
         console.log('Chatbase script loaded, waiting for initialization...');
         console.log('Chatbase loaded on wiki');
       
        // Chatbase sometimes needs a manual trigger
        setTimeout(function() {
            console.log('Attempting to initialize Chatbase...');
           
            // Try to manually trigger the chat bubble
            const chatbaseBubble = document.querySelector('[class*="chatbase"], [id*="chatbase"]');
            if (chatbaseBubble) {
                console.log('Chatbase bubble found, adding click handler...');
                chatbaseBubble.style.display = 'block';
                chatbaseBubble.style.visibility = 'visible';
               
                // Ensure it's clickable
                chatbaseBubble.onclick = function(e) {
                    e.preventDefault();
                    console.log('Chat bubble clicked, opening chat...');
                    // Chatbase should handle the rest
                };
            } else {
                console.warn('Chatbase bubble not found in DOM');
                createFunctionalFallback();
            }
        }, 2000);
     };
     };
      
      
     script.onerror = function() {
     script.onerror = function() {
         console.error('Chatbase failed to load, creating functional fallback...');
         console.log('Chatbase failed, using wiki chat bubble');
        createFunctionalFallback();
     };
     };
      
      
Line 51: Line 25:
});
});


// Create a working fallback chat interface
// Add chat bubble specifically for wiki pages
function createFunctionalFallback() {
function addChatBubbleToWiki() {
     console.log('Creating functional chat fallback...');
     // Remove any existing chat bubbles first
    const existingBubbles = document.querySelectorAll('[id="helix-wiki-chat"]');
    existingBubbles.forEach(bubble => bubble.remove());
      
      
     const chatBubble = document.createElement('div');
     const chatBubble = document.createElement('div');
     chatBubble.innerHTML = '💬 Ask Helix AI';
    chatBubble.id = 'helix-wiki-chat';
     chatBubble.innerHTML = '💬 AI Assistant';
     chatBubble.style.cssText = `
     chatBubble.style.cssText = `
         position: fixed;
         position: fixed;
Line 85: Line 62:
     };
     };
      
      
     // Create a simple chat interface
     // Make it do something useful
     chatBubble.onclick = function() {
     chatBubble.onclick = function() {
         // Create modal chat interface
         // Show a helpful modal for wiki users
        const chatModal = document.createElement('div');
        showWikiHelpModal();
        chatModal.style.cssText = `
    };
            position: fixed;
   
            top: 50%;
    document.body.appendChild(chatBubble);
            left: 50%;
    console.log('Wiki chat bubble added');
            transform: translate(-50%, -50%);
}
            background: white;
 
            padding: 30px;
// Helpful modal for wiki users
            border-radius: 15px;
function showWikiHelpModal() {
            box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    const modal = document.createElement('div');
            z-index: 10001;
    modal.style.cssText = `
            min-width: 300px;
        position: fixed;
            text-align: center;
        top: 50%;
        `;
        left: 50%;
       
        transform: translate(-50%, -50%);
        chatModal.innerHTML = `
        background: white;
            <h3 style="margin: 0 0 15px 0; color: #333;">Helix AI Assistant</h3>
        padding: 30px;
            <p style="color: #666; margin-bottom: 20px;">Chat functionality coming soon!</p>
        border-radius: 15px;
             <p style="color: #888; font-size: 12px; margin-bottom: 15px;">For now, please visit the wiki for assistance.</p>
        box-shadow: 0 10px 40px rgba(0,0,0,0.3);
             <button onclick="this.parentElement.remove()" style="
        z-index: 10001;
        min-width: 400px;
        max-width: 90vw;
        text-align: left;
    `;
   
    modal.innerHTML = `
        <h3 style="margin: 0 0 15px 0; color: #333; border-bottom: 2px solid #667eea; padding-bottom: 10px;">Helix AI Assistant</h3>
        <p style="color: #666; margin-bottom: 15px;">I can help you with:</p>
        <ul style="color: #666; margin-bottom: 20px; padding-left: 20px;">
            <li>Wiki editing and formatting</li>
            <li>Finding information in the Helix Project</li>
            <li>MediaWiki syntax help</li>
             <li>Project documentation</li>
        </ul>
        <p style="color: #888; font-size: 12px; margin-bottom: 20px; background: #f5f5f5; padding: 10px; border-radius: 5px;">
            <strong>Note:</strong> Full chat integration coming soon. For now, you can ask questions in the wiki discussion pages.
        </p>
        <div style="text-align: center;">
             <button onclick="closeModal()" style="
                 background: #667eea;
                 background: #667eea;
                 color: white;
                 color: white;
Line 114: Line 110:
                 border-radius: 5px;
                 border-radius: 5px;
                 cursor: pointer;
                 cursor: pointer;
             ">Close</button>
                margin: 0 5px;
        `;
             ">Got it!</button>
       
            <button onclick="window.location.href='/wiki/Help:Contents'" style="
        // Add overlay
                background: transparent;
        const overlay = document.createElement('div');
                color: #667eea;
        overlay.style.cssText = `
                border: 1px solid #667eea;
            position: fixed;
                padding: 10px 20px;
            top: 0;
                border-radius: 5px;
            left: 0;
                cursor: pointer;
            width: 100%;
                margin: 0 5px;
            height: 100%;
             ">Wiki Help</button>
            background: rgba(0,0,0,0.5);
         </div>
            z-index: 10000;
     `;
        `;
        overlay.onclick = function() {
             chatModal.remove();
            overlay.remove();
         };
       
        document.body.appendChild(overlay);
        document.body.appendChild(chatModal);
     };
      
      
     document.body.appendChild(chatBubble);
     // Add overlay
    console.log('Functional fallback chat bubble created!');
     const overlay = document.createElement('div');
}
     overlay.style.cssText = `
 
// Alternative: Link to a specific wiki help page
function createWikiHelpBubble() {
     const helpBubble = document.createElement('a');
     helpBubble.href = '/wiki/Helix_AI_Assistant';
    helpBubble.innerHTML = '💬 Get AI Help';
    helpBubble.style.cssText = `
         position: fixed;
         position: fixed;
         bottom: 20px;
         top: 0;
         right: 20px;
         left: 0;
         background: #007cba;
         width: 100%;
         color: white;
         height: 100%;
         padding: 15px 20px;
         background: rgba(0,0,0,0.5);
        border-radius: 25px;
         z-index: 10000;
        cursor: pointer;
        z-index: 1000;
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
         font-family: sans-serif;
        font-size: 14px;
        text-decoration: none;
        display: block;
     `;
     `;
     document.body.appendChild(helpBubble);
    overlay.id = 'helix-modal-overlay';
   
    // Close function
    window.closeModal = function() {
        modal.remove();
        overlay.remove();
    };
   
    overlay.onclick = window.closeModal;
   
    document.body.appendChild(overlay);
     document.body.appendChild(modal);
}
}

Revision as of 11:39, 7 October 2025

/* Any JavaScript here will be loaded for all users on every page load. */
// Helix Project AI Assistant - Chatbase with Fallback Bubble
window.addEventListener('load', function() {
    console.log('Loading Helix AI Assistant for Wiki...');
    
    // Add the chat bubble to wiki pages
    addChatBubbleToWiki();
    
    // Your existing Chatbase integration
    var script = document.createElement('script');
    script.src = 'https://www.chatbase.co/embed.min.js';
    script.setAttribute('chatbotId', 'i65eBj3COxUlFEU_Lsrw0');
    script.setAttribute('domain', 'www.chatbase.co');
    script.defer = true;
    
    script.onload = function() {
        console.log('Chatbase loaded on wiki');
    };
    
    script.onerror = function() {
        console.log('Chatbase failed, using wiki chat bubble');
    };
    
    document.body.appendChild(script);
});

// Add chat bubble specifically for wiki pages
function addChatBubbleToWiki() {
    // Remove any existing chat bubbles first
    const existingBubbles = document.querySelectorAll('[id="helix-wiki-chat"]');
    existingBubbles.forEach(bubble => bubble.remove());
    
    const chatBubble = document.createElement('div');
    chatBubble.id = 'helix-wiki-chat';
    chatBubble.innerHTML = '💬 AI Assistant';
    chatBubble.style.cssText = `
        position: fixed;
        bottom: 20px;
        right: 20px;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        padding: 15px 20px;
        border-radius: 25px;
        cursor: pointer;
        z-index: 10000;
        box-shadow: 0 4px 20px rgba(0,0,0,0.3);
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
        font-size: 14px;
        font-weight: 600;
        transition: all 0.3s ease;
    `;
    
    // Add hover effects
    chatBubble.onmouseenter = function() {
        this.style.transform = 'scale(1.1)';
        this.style.boxShadow = '0 6px 25px rgba(0,0,0,0.4)';
    };
    
    chatBubble.onmouseleave = function() {
        this.style.transform = 'scale(1)';
        this.style.boxShadow = '0 4px 20px rgba(0,0,0,0.3)';
    };
    
    // Make it do something useful
    chatBubble.onclick = function() {
        // Show a helpful modal for wiki users
        showWikiHelpModal();
    };
    
    document.body.appendChild(chatBubble);
    console.log('Wiki chat bubble added');
}

// Helpful modal for wiki users
function showWikiHelpModal() {
    const modal = document.createElement('div');
    modal.style.cssText = `
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        background: white;
        padding: 30px;
        border-radius: 15px;
        box-shadow: 0 10px 40px rgba(0,0,0,0.3);
        z-index: 10001;
        min-width: 400px;
        max-width: 90vw;
        text-align: left;
    `;
    
    modal.innerHTML = `
        <h3 style="margin: 0 0 15px 0; color: #333; border-bottom: 2px solid #667eea; padding-bottom: 10px;">Helix AI Assistant</h3>
        <p style="color: #666; margin-bottom: 15px;">I can help you with:</p>
        <ul style="color: #666; margin-bottom: 20px; padding-left: 20px;">
            <li>Wiki editing and formatting</li>
            <li>Finding information in the Helix Project</li>
            <li>MediaWiki syntax help</li>
            <li>Project documentation</li>
        </ul>
        <p style="color: #888; font-size: 12px; margin-bottom: 20px; background: #f5f5f5; padding: 10px; border-radius: 5px;">
            <strong>Note:</strong> Full chat integration coming soon. For now, you can ask questions in the wiki discussion pages.
        </p>
        <div style="text-align: center;">
            <button onclick="closeModal()" style="
                background: #667eea;
                color: white;
                border: none;
                padding: 10px 20px;
                border-radius: 5px;
                cursor: pointer;
                margin: 0 5px;
            ">Got it!</button>
            <button onclick="window.location.href='/wiki/Help:Contents'" style="
                background: transparent;
                color: #667eea;
                border: 1px solid #667eea;
                padding: 10px 20px;
                border-radius: 5px;
                cursor: pointer;
                margin: 0 5px;
            ">Wiki Help</button>
        </div>
    `;
    
    // Add overlay
    const overlay = document.createElement('div');
    overlay.style.cssText = `
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,0.5);
        z-index: 10000;
    `;
    overlay.id = 'helix-modal-overlay';
    
    // Close function
    window.closeModal = function() {
        modal.remove();
        overlay.remove();
    };
    
    overlay.onclick = window.closeModal;
    
    document.body.appendChild(overlay);
    document.body.appendChild(modal);
}