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

From DQWiki
Jump to navigationJump to search
No edit summary
No edit summary
Line 2: Line 2:
(function() {
(function() {
     var username = mw.config.get('wgUserName');
     var username = mw.config.get('wgUserName');
     var iframeUrl = 'https://npc-forge-62728542440.asia-southeast1.run.app/lore?isWidget=true';
     var iframeUrl = 'https://npc-forge-62728542440.asia-southeast1.run.app/widget';
     if (username) {
     if (username) {
         iframeUrl += '&user=' + encodeURIComponent(username);
         iframeUrl += '?user=' + encodeURIComponent(username);
    } else {
        iframeUrl += '?guest=Traveler';
     }
     }


Line 10: Line 12:
     var widgetContainer = document.createElement('div');
     var widgetContainer = document.createElement('div');
     widgetContainer.id = 'lorekeeper-widget-container';
     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;';
     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 = '600px'; // Wide enough for the compact view + padding
     widgetContainer.style.width = '300px';  
     widgetContainer.style.height = '800px';
     widgetContainer.style.height = '120px';


     var iframe = document.createElement('iframe');
     var iframe = document.createElement('iframe');
Line 22: Line 24:
     document.body.appendChild(widgetContainer);
     document.body.appendChild(widgetContainer);


     // ? NEW: Listen for the widget telling the Wiki to "Grow"
     // ? NEW: Listen for the widget telling the Wiki to "Grow" and "Shrink"
     window.addEventListener('message', function(event) {
     window.addEventListener('message', function(event) {
        // Updated to the correct App Hosting domain
         if (event.origin !== 'https://npc-forge-62728542440.asia-southeast1.run.app') return;
         if (event.origin !== 'https://npc-forge-62728542440.asia-southeast1.run.app') return;
         if (event.data.type === 'lorekeeper-resize') {
         if (event.data.type === 'lorekeeper-resize') {
             widgetContainer.style.width = event.data.width + 'px';
             widgetContainer.style.width = event.data.width + 'px';
            widgetContainer.style.height = event.data.height + 'px';
         }
         }
     });
     });
})();
})();

Revision as of 10:16, 25 February 2026

/* Lorekeeper Widget Loader - Advanced Version */
(function() {
    var username = mw.config.get('wgUserName');
    var iframeUrl = 'https://npc-forge-62728542440.asia-southeast1.run.app/widget';
    if (username) {
        iframeUrl += '?user=' + encodeURIComponent(username);
    } else {
        iframeUrl += '?guest=Traveler';
    }

    // 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 = '300px'; 
    widgetContainer.style.height = '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);

    // ? NEW: Listen for the widget telling the Wiki to "Grow" and "Shrink"
    window.addEventListener('message', function(event) {
        if (event.origin !== 'https://npc-forge-62728542440.asia-southeast1.run.app') return;
        if (event.data.type === 'lorekeeper-resize') {
            widgetContainer.style.width = event.data.width + 'px';
            widgetContainer.style.height = event.data.height + 'px';
        }
    });
})();