User:Jono Bean/common.js

From DQWiki
Jump to navigationJump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Lorekeeper Widget Loader - Advanced Version */
(function() {
    var username = mw.config.get('wgUserName');
    var iframeUrl = 'https://npc-forge-62728542440.asia-southeast1.run.app/lore?isWidget=true';
    if (username) {
        iframeUrl += '&user=' + encodeURIComponent(username);
    }

    // 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;';
    widgetContainer.style.width = '600px'; // Wide enough for the compact view + padding
    widgetContainer.style.height = '800px';

    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"
    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.data.type === 'lorekeeper-resize') {
            widgetContainer.style.width = event.data.width + 'px';
        }
    });
})();