User:Jono Bean/common.js: Difference between revisions

From DQWiki
Jump to navigationJump to search
mNo edit summary
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Lorekeeper Standalone Terminal v6.1 - Royal Carzala Theme */
/* Lorekeeper Widget Loader - v1.1.3 (Hardened Responsive Iframe) */
(function() {
(function() {
     var checkCount = 0;
     var username = mw.config.get('wgUserName');
     var initTimer = setInterval(function() {
    var isMobileParent = window.innerWidth < 768; // Measure the true Wiki window size
         if (document.body) { clearInterval(initTimer); setupLore(); }
   
        if (checkCount++ > 100) clearInterval(initTimer);
    // Uses the correct Firebase Hosted App URL
     }, 100);
    var iframeUrl = 'https://npc-forge--npc-forge-qh4gc.asia-southeast1.hosted.app/widget';
   
     var params = [];
    if (username) {
         params.push('user=' + encodeURIComponent(username));
    } else {
        params.push('guest=Traveler');
    }
   
    // Tell the iframe if the user is ACTUALLY on mobile
    if (isMobileParent) {
        params.push('isMobile=true');
    }
   
    if (params.length > 0) {
        iframeUrl += '?' + params.join('&');
     }


     function setupLore() {
     // Create a container that doesn't block the Wiki
        if (document.getElementById('lore-terminal-btn')) return;
    var widgetContainer = document.createElement('div');
    widgetContainer.id = 'lorekeeper-widget-container';
    widgetContainer.style.cssText = 'position:fixed; bottom:0; right:0; z-index:99999; pointer-events:none; transition: width 0.3s ease, height 0.3s ease;';
    widgetContainer.style.width = isMobileParent ? '80px' : '300px';
    widgetContainer.style.height = isMobileParent ? '80px' : '120px';


        var css =  
    var iframe = document.createElement('iframe');
            '#lore-chat::-webkit-scrollbar { width: 5px; }' +
    iframe.src = iframeUrl;
            '#lore-chat::-webkit-scrollbar-thumb { background: #f97316; border-radius: 10px; }' +
    iframe.style.cssText = 'width:100%; height:100%; border:none; background:transparent; pointer-events:auto;';
            '.lore-msg { margin-bottom: 12px; padding: 12px 16px; border-radius: 15px; font-size: 14px; line-height: 1.5; }' +
    iframe.setAttribute('allow', 'clipboard-write'); // For links/sharing later
            '.lore-user { background: #f97316; color: #000; align-self: flex-end; margin-left: 35px; border-bottom-right-radius: 4px; font-weight: 500; }' +
            '.lore-ai { background: #24140e; color: #f7f3e8; align-self: flex-start; margin-right: 35px; border-left: 4px solid #f97316; border-bottom-left-radius: 4px; }';
       
        var style = document.createElement('style');
        style.type = 'text/css';
        style.appendChild(document.createTextNode(css));
        document.head.appendChild(style);


        var btn = document.createElement('div');
    widgetContainer.appendChild(iframe);
        btn.id = 'lore-terminal-btn';
    document.body.appendChild(widgetContainer);
        btn.innerHTML = '&#10024;';
        btn.setAttribute('style', 'position:fixed !important; bottom:25px !important; right:25px !important; width:65px !important; height:65px !important; background:#2d140e !important; border-radius:50% !important; display:flex !important; align-items:center !important; justify-content:center !important; font-size:32px !important; cursor:pointer !important; box-shadow:0 10px 30px rgba(0,0,0,0.6) !important; z-index:9999999 !important; border:3px solid #f97316 !important;');


        var box = document.createElement('div');
    // Listen for the widget telling the Wiki to "Grow" and "Shrink"
         box.id = 'lore-terminal-box';
    window.addEventListener('message', function(event) {
        box.setAttribute('style', 'position:fixed !important; bottom:105px !important; right:25px !important; width:410px !important; height:600px !important; background:#1a0d09 !important; border:1px solid #412a23 !important; border-radius:24px !important; display:none; flex-direction:column !important; box-shadow:0 30px 80px rgba(0,0,0,0.9) !important; z-index:9999999 !important; color:#f7f3e8 !important; font-family:serif !important; overflow:hidden;');
        // Enforce secure origin check for the correct App Hosting domain
         if (event.origin !== 'https://npc-forge--npc-forge-qh4gc.asia-southeast1.hosted.app') return;
          
          
         box.innerHTML =  
         if (event.data.type === 'lorekeeper-resize') {
             '<div style="padding:18px 20px; border-bottom:1px solid #412a23; background:rgba(249,115,22,0.05); display:flex; justify-content:space-between; align-items:center;">' +
             var w = event.data.width;
                '<div><b style="color:#f97316; font-size:16px; letter-spacing:1px; text-transform:uppercase;">Lorekeeper</b><br><small style="opacity:0.6; font-size:10px;">Duchy of Carzala - Seagate Archives</small></div>' +
            var h = event.data.height;
                '<span id="lore-close" style="cursor:pointer; font-size:24px; opacity:0.5; color:#f97316;">&times;</span>' +
            // Handle both pixel numbers (desktop) and string values like "100vw" (mobile)
             '</div>' +
            widgetContainer.style.width = (typeof w === 'number') ? w + 'px' : w;
            '<div id="lore-chat" style="flex:1; overflow-y:auto; padding:20px; display:flex; flex-direction:column; background:#1a0d09;">' +
             widgetContainer.style.height = (typeof h === 'number') ? h + 'px' : h;
                '<div class="lore-msg lore-ai">Greetings, Traveler. I am the Scribe of the Seagate Archives. What knowledge of <b>Carzala</b> do you seek today?</div>' +
        }
            '</div>' +
    });
            '<div style="padding
 
    // Optional: Resync if they resize the window wildly (desktop to mobile mode live)
    window.addEventListener('resize', function() {
        var newIsMobile = window.innerWidth < 768;
        if (newIsMobile !== isMobileParent) {
            isMobileParent = newIsMobile;
            // You could reload the iframe here, but keeping it simple is usually safest.
        }
    });
})();

Latest revision as of 08:07, 1 March 2026

/* Lorekeeper Widget Loader - v1.1.3 (Hardened Responsive Iframe) */
(function() {
    var username = mw.config.get('wgUserName');
    var isMobileParent = window.innerWidth < 768; // Measure the true Wiki window size
    
    // Uses the correct Firebase Hosted App URL
    var iframeUrl = 'https://npc-forge--npc-forge-qh4gc.asia-southeast1.hosted.app/widget';
    
    var params = [];
    if (username) {
        params.push('user=' + encodeURIComponent(username));
    } else {
        params.push('guest=Traveler');
    }
    
    // Tell the iframe if the user is ACTUALLY on mobile
    if (isMobileParent) {
        params.push('isMobile=true');
    }
    
    if (params.length > 0) {
        iframeUrl += '?' + params.join('&');
    }

    // Create a container that doesn't block the Wiki
    var widgetContainer = document.createElement('div');
    widgetContainer.id = 'lorekeeper-widget-container';
    widgetContainer.style.cssText = 'position:fixed; bottom:0; right:0; z-index:99999; pointer-events:none; transition: width 0.3s ease, height 0.3s ease;';
    widgetContainer.style.width = isMobileParent ? '80px' : '300px'; 
    widgetContainer.style.height = isMobileParent ? '80px' : '120px';

    var iframe = document.createElement('iframe');
    iframe.src = iframeUrl;
    iframe.style.cssText = 'width:100%; height:100%; border:none; background:transparent; pointer-events:auto;';
    iframe.setAttribute('allow', 'clipboard-write'); // For links/sharing later

    widgetContainer.appendChild(iframe);
    document.body.appendChild(widgetContainer);

    // Listen for the widget telling the Wiki to "Grow" and "Shrink"
    window.addEventListener('message', function(event) {
        // Enforce secure origin check for the correct App Hosting domain
        if (event.origin !== 'https://npc-forge--npc-forge-qh4gc.asia-southeast1.hosted.app') return;
        
        if (event.data.type === 'lorekeeper-resize') {
            var w = event.data.width;
            var h = event.data.height;
            // Handle both pixel numbers (desktop) and string values like "100vw" (mobile)
            widgetContainer.style.width = (typeof w === 'number') ? w + 'px' : w;
            widgetContainer.style.height = (typeof h === 'number') ? h + 'px' : h;
        }
    });

    // Optional: Resync if they resize the window wildly (desktop to mobile mode live)
    window.addEventListener('resize', function() {
        var newIsMobile = window.innerWidth < 768;
        if (newIsMobile !== isMobileParent) {
            isMobileParent = newIsMobile;
            // You could reload the iframe here, but keeping it simple is usually safest.
        }
    });
})();