imported>Dawning
(by SublimeText.Mediawiker)
imported>Dawning
(by SublimeText.Mediawiker)
Line 86: Line 86:
     console.log('Dynamic GIF Displayer: Script loading...');
     console.log('Dynamic GIF Displayer: Script loading...');
      
      
    // Configuration
     const CONFIG = {
     const CONFIG = {
         containerClass: 'dynamic-gif-container',
         containerClass: 'dynamic-gif-container',
Line 92: Line 91:
         autoExpand: true,
         autoExpand: true,
         expandDelay: 200,
         expandDelay: 200,
         collapseDelay: 1000
         collapseDelay: 1000,
        maxGifSize: 2000,
        allowedDomains: [window.location.origin]
     };
     };
      
      
Line 98: Line 99:
     let collapseTimer = null;
     let collapseTimer = null;
     let currentGif = null;
     let currentGif = null;
   
    function createTextElement(tag, className, text) {
        const element = document.createElement(tag);
        element.className = className;
        element.textContent = text;
        return element;
    }
   
    function isValidGifUrl(url) {
        try {
            if (!url.startsWith('http://') && !url.startsWith('https://')) {
                return true;
            }
           
            const parsed = new URL(url);
            return CONFIG.allowedDomains.some(domain => {
                try {
                    const allowedUrl = new URL(domain);
                    return parsed.origin === allowedUrl.origin;
                } catch {
                    return false;
                }
            });
        } catch {
            return false;
        }
    }
   
    function sanitizeGifSize(sizeStr) {
        const size = parseInt(sizeStr, 10);
        if (isNaN(size) || size < 50 || size > CONFIG.maxGifSize) {
            return 400;
        }
        return size;
    }
      
      
     function init() {
     function init() {
Line 106: Line 142:
          
          
         containers.forEach(container => {
         containers.forEach(container => {
             console.log('Dynamic GIF Displayer: Setting up container', container.id);
             console.log('Dynamic GIF Displayer: Setting up container', container.id || 'unnamed');
             setupContainer(container);
             setupContainer(container);
             attachTooltipListeners(container);
             attachTooltipListeners(container);
Line 132: Line 168:
          
          
         const gifMap = buildGifMap(container);
         const gifMap = buildGifMap(container);
         console.log('Dynamic GIF Displayer: GIF map', gifMap);
         console.log('Dynamic GIF Displayer: GIF map built with', Object.keys(gifMap).length, 'entries');
          
          
         const tooltips = document.querySelectorAll('.advanced-tooltip');
         const tooltips = document.querySelectorAll('.advanced-tooltip');
Line 143: Line 179:
             const skillName = skillTitle.textContent.trim();
             const skillName = skillTitle.textContent.trim();
             const gifUrl = gifMap[skillName];
             const gifUrl = gifMap[skillName];
           
            console.log('Dynamic GIF Displayer: Processing tooltip:', skillName, 'GIF:', gifUrl);
              
              
             if (gifUrl) {
             if (gifUrl) {
Line 169: Line 203:
             return gifMap;
             return gifMap;
         }
         }
       
        console.log('Dynamic GIF Displayer: Raw list data:', listData);
          
          
         const entries = listData.split(';').filter(e => e.trim());
         const entries = listData.split(';').filter(e => e.trim());
Line 176: Line 208:
          
          
         entries.forEach(entry => {
         entries.forEach(entry => {
             const parts = entry.split(':');
             const colonIndex = entry.indexOf(':');
             if (parts.length >= 2) {
             if (colonIndex === -1) return;
                const skillName = parts[0].trim();
           
                const gifFile = parts.slice(1).join(':').trim();
            const skillName = entry.substring(0, colonIndex).trim();
            const gifFile = entry.substring(colonIndex + 1).trim();
           
            if (skillName && gifFile) {
                // Sanitize the file path
                const sanitizedFile = gifFile.replace(/[<>'"]/g, '');
               
                let gifUrl;
                if (typeof mw !== 'undefined' && mw.config) {
                    gifUrl = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/images/' + sanitizedFile;
                } else {
                    gifUrl = '/images/' + sanitizedFile;
                }
                  
                  
                 if (skillName && gifFile) {
                 if (isValidGifUrl(gifUrl)) {
                    let gifUrl;
                    if (typeof mw !== 'undefined' && mw.config) {
                        gifUrl = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/images/' + gifFile;
                    } else {
                        gifUrl = '/images/' + gifFile;
                    }
                   
                     gifMap[skillName] = gifUrl;
                     gifMap[skillName] = gifUrl;
                     console.log('Dynamic GIF Displayer: Mapped "' + skillName + '" to', gifUrl);
                     console.log('Dynamic GIF Displayer: Mapped "' + skillName + '" to validated URL');
                } else {
                    console.warn('Dynamic GIF Displayer: Rejected invalid URL for', skillName);
                 }
                 }
             }
             }
Line 209: Line 248:


     function showGif(container, gifUrl, skillName) {
     function showGif(container, gifUrl, skillName) {
         console.log('Dynamic GIF Displayer: Showing GIF for', skillName, gifUrl);
         console.log('Dynamic GIF Displayer: Showing GIF for', skillName);
          
          
         const displayArea = container.querySelector('.' + CONFIG.displayClass);
         const displayArea = container.querySelector('.' + CONFIG.displayClass);
         if (!displayArea) return;
         if (!displayArea) return;
          
          
         const gifSize = container.getAttribute('data-gif-size') || '400';
         const gifSize = sanitizeGifSize(container.getAttribute('data-gif-size'));
          
          
         if (!container.classList.contains('expanded')) {
         if (!container.classList.contains('expanded')) {
Line 236: Line 275:
                 const gifFilename = gifUrl.split('/').pop();
                 const gifFilename = gifUrl.split('/').pop();
                 if (gifFilename.toLowerCase() === 'blank' || gifFilename.toLowerCase() === 'blank.gif') {
                 if (gifFilename.toLowerCase() === 'blank' || gifFilename.toLowerCase() === 'blank.gif') {
                     imgContainer.innerHTML = '<div class="gif-placeholder">This node does not require a GIF due to its simplicity.</div>';
                     const placeholderDiv = createTextElement('div', 'gif-placeholder',
                        'This node does not require a GIF due to its simplicity.');
                    imgContainer.innerHTML = '';
                    imgContainer.appendChild(placeholderDiv);
                     imgContainer.classList.remove('loading');
                     imgContainer.classList.remove('loading');
                 } else {
                 } else {
Line 254: Line 296:
                      
                      
                     img.onerror = () => {
                     img.onerror = () => {
                         imgContainer.innerHTML = '<div class="gif-error">GIF not found: ' + gifUrl + '</div>';
                         const errorDiv = createTextElement('div', 'gif-error',
                            'GIF not found: ' + gifUrl);
                        imgContainer.innerHTML = '';
                        imgContainer.appendChild(errorDiv);
                         imgContainer.classList.remove('loading');
                         imgContainer.classList.remove('loading');
                         console.error('Dynamic GIF Displayer: Failed to load GIF', gifUrl);
                         console.error('Dynamic GIF Displayer: Failed to load GIF', gifUrl);
Line 282: Line 327:
                  
                  
                 if (imgContainer) {
                 if (imgContainer) {
                     imgContainer.innerHTML = '<div class="gif-placeholder">Hover over a skill node to see its demonstration</div>';
                     const placeholderDiv = createTextElement('div', 'gif-placeholder',
                        'Hover over a skill node to see its demonstration');
                    imgContainer.innerHTML = '';
                    imgContainer.appendChild(placeholderDiv);
                     imgContainer.style.height = '';
                     imgContainer.style.height = '';
                     imgContainer.style.minHeight = '';
                     imgContainer.style.minHeight = '';
Line 300: Line 348:
     window.toggleGifDisplay = function(containerId) {
     window.toggleGifDisplay = function(containerId) {
         console.log('Dynamic GIF Displayer: Toggle clicked for', containerId);
         console.log('Dynamic GIF Displayer: Toggle clicked for', containerId);
       
        if (typeof containerId !== 'string' || !containerId.match(/^[a-zA-Z0-9_-]+$/)) {
            console.error('Dynamic GIF Displayer: Invalid container ID');
            return;
        }
       
         const container = document.getElementById(containerId);
         const container = document.getElementById(containerId);
         if (!container) {
         if (!container) {
Line 321: Line 375:
                  
                  
                 if (imgContainer) {
                 if (imgContainer) {
                     imgContainer.innerHTML = '<div class="gif-placeholder">Hover over a skill node to see its demonstration</div>';
                     const placeholderDiv = createTextElement('div', 'gif-placeholder',
                        'Hover over a skill node to see its demonstration');
                    imgContainer.innerHTML = '';
                    imgContainer.appendChild(placeholderDiv);
                     imgContainer.style.height = '';
                     imgContainer.style.height = '';
                     imgContainer.style.minHeight = '';
                     imgContainer.style.minHeight = '';
Line 336: Line 393:
         }
         }
     };
     };
   
 
     if (document.readyState === 'loading') {
     if (document.readyState === 'loading') {
         document.addEventListener('DOMContentLoaded', init);
         document.addEventListener('DOMContentLoaded', init);

Revision as of 21:36, 15 October 2025

/* Any JavaScript here will be loaded for all users on every page load. */

/* DRUID */
$(function () {
  $(".druid-main-images-label").off("click");
  $(".druid-main-images-label").click(function () {
    var $parent = $(this).closest(".druid-container");
    $parent.find(".druid-toggleable").removeClass("focused");
    var i = $(this).attr("data-druid");
    $parent.find(".druid-toggleable[data-druid=" + i + "]").addClass("focused");
  });

  $(".druid-collapsible").off("click");
  $(".druid-collapsible").click(function () {
    var kind = $(this).attr("data-druid-section");
    $(this).toggleClass("druid-collapsible-collapsed");
    $(this)
      .closest(".druid-container")
      .find("[data-druid-section-row=" + kind + "]")
      .toggleClass("druid-collapsed");
  });
});
/* End DRUID */

/* [[Template:Spoiler]] */
$(function () {
	$('.spoiler-content')
	.off('click') // in case this code is loaded twice
	.on('click', function(e){
		$(this).toggleClass('show');
	}).find('a').on('click', function(e){
		e.stopPropagation();
	});

});
/* End Template:Spoiler */


/* Link to imported modules from Lua code */
$(function() {
    var config = mw.config.get([
        'wgCanonicalNamespace',
        'wgFormattedNamespaces'
    ]);
    if (config.wgCanonicalNamespace !== 'Module') {
        return;
    }
    var localizedNamespace = config.wgFormattedNamespaces[828];
    $('.s1, .s2, .s').each(function() {
        var $this = $(this);
        var html = $this.html();
        var quote = html[0];
        var isLongStringQuote = quote === '[';
        var quoteRE = new RegExp('^\\' + quote + '|\\' + quote + '$', 'g');
        if (isLongStringQuote) {
            quoteRE = /^\[\[|\]\]$/g;
        }
        var name = html.replace(quoteRE, '');
        var isEnglishPrefix = name.startsWith('Module:');
        var isLocalizedPrefix = name.startsWith(localizedNamespace + ':');
        var isDevPrefix = name.startsWith('Dev:');
        if (isEnglishPrefix || isLocalizedPrefix || isDevPrefix) {
            var attrs = {
                href: mw.util.getUrl(name)
            };
            if (isDevPrefix) {
                attrs.href = 'https://commons.wiki.gg/wiki/Module:' + mw.util.wikiUrlencode(name.replace('Dev:', ''));
                attrs.target = '_blank';
                attrs.rel = 'noopener';
            }
            var link = mw.html.element('a', attrs, name);
            var str = quote + link + quote;
            if (isLongStringQuote) {
                str = '[[' + link + ']]';
            }
            $this.html(str);
        }
    });
});

/* dynamic gif displayer ONLY TOUCH IF YOU KNOW WHAT YOU ARE DOING */

(function() {
    'use strict';
    
    console.log('Dynamic GIF Displayer: Script loading...');
    
    const CONFIG = {
        containerClass: 'dynamic-gif-container',
        displayClass: 'gif-display-area',
        autoExpand: true,
        expandDelay: 200,
        collapseDelay: 1000,
        maxGifSize: 2000, 
        allowedDomains: [window.location.origin] 
    };
    
    let expandTimer = null;
    let collapseTimer = null;
    let currentGif = null;
    
    function createTextElement(tag, className, text) {
        const element = document.createElement(tag);
        element.className = className;
        element.textContent = text;
        return element;
    }
    
    function isValidGifUrl(url) {
        try {
            if (!url.startsWith('http://') && !url.startsWith('https://')) {
                return true;
            }
            
            const parsed = new URL(url);
            return CONFIG.allowedDomains.some(domain => {
                try {
                    const allowedUrl = new URL(domain);
                    return parsed.origin === allowedUrl.origin;
                } catch {
                    return false;
                }
            });
        } catch {
            return false;
        }
    }
    
    function sanitizeGifSize(sizeStr) {
        const size = parseInt(sizeStr, 10);
        if (isNaN(size) || size < 50 || size > CONFIG.maxGifSize) {
            return 400; 
        }
        return size;
    }
    
    function init() {
        console.log('Dynamic GIF Displayer: Initializing...');
        
        const containers = document.querySelectorAll('.' + CONFIG.containerClass);
        console.log('Dynamic GIF Displayer: Found', containers.length, 'containers');
        
        containers.forEach(container => {
            console.log('Dynamic GIF Displayer: Setting up container', container.id || 'unnamed');
            setupContainer(container);
            attachTooltipListeners(container);
        });
    }
    
    function setupContainer(container) {
        const displayArea = container.querySelector('.' + CONFIG.displayClass);
        if (!displayArea) {
            console.error('Dynamic GIF Displayer: No display area found');
            return;
        }
        
        displayArea.addEventListener('mouseenter', () => {
            clearTimeout(collapseTimer);
        });
        
        displayArea.addEventListener('mouseleave', () => {
            scheduleCollapse(container);
        });
    }
    
    function attachTooltipListeners(container) {
        console.log('Dynamic GIF Displayer: Attaching tooltip listeners...');
        
        const gifMap = buildGifMap(container);
        console.log('Dynamic GIF Displayer: GIF map built with', Object.keys(gifMap).length, 'entries');
        
        const tooltips = document.querySelectorAll('.advanced-tooltip');
        console.log('Dynamic GIF Displayer: Found', tooltips.length, 'tooltips');
        
        tooltips.forEach((tooltip) => {
            const skillTitle = tooltip.querySelector('.skill-title');
            if (!skillTitle) return;
            
            const skillName = skillTitle.textContent.trim();
            const gifUrl = gifMap[skillName];
            
            if (gifUrl) {
                tooltip.removeEventListener('mouseenter', tooltip._gifHoverHandler);
                tooltip.removeEventListener('mouseleave', tooltip._gifLeaveHandler);
                
                tooltip._gifHoverHandler = () => handleTooltipHover(container, gifUrl, skillName);
                tooltip._gifLeaveHandler = () => scheduleCollapse(container);
                
                tooltip.addEventListener('mouseenter', tooltip._gifHoverHandler);
                tooltip.addEventListener('mouseleave', tooltip._gifLeaveHandler);
                
                console.log('Dynamic GIF Displayer: Attached listeners to', skillName);
            }
        });
    }
    
    function buildGifMap(container) {
        const gifMap = {};
        const listData = container.getAttribute('data-gif-list');
        
        if (!listData) {
            console.error('Dynamic GIF Displayer: No data-gif-list attribute found');
            return gifMap;
        }
        
        const entries = listData.split(';').filter(e => e.trim());
        console.log('Dynamic GIF Displayer: Found', entries.length, 'entries');
        
        entries.forEach(entry => {
            const colonIndex = entry.indexOf(':');
            if (colonIndex === -1) return;
            
            const skillName = entry.substring(0, colonIndex).trim();
            const gifFile = entry.substring(colonIndex + 1).trim();
            
            if (skillName && gifFile) {
                // Sanitize the file path
                const sanitizedFile = gifFile.replace(/[<>'"]/g, '');
                
                let gifUrl;
                if (typeof mw !== 'undefined' && mw.config) {
                    gifUrl = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/images/' + sanitizedFile;
                } else {
                    gifUrl = '/images/' + sanitizedFile;
                }
                
                if (isValidGifUrl(gifUrl)) {
                    gifMap[skillName] = gifUrl;
                    console.log('Dynamic GIF Displayer: Mapped "' + skillName + '" to validated URL');
                } else {
                    console.warn('Dynamic GIF Displayer: Rejected invalid URL for', skillName);
                }
            }
        });
        
        return gifMap;
    }
    
    function handleTooltipHover(container, gifUrl, skillName) {
        console.log('Dynamic GIF Displayer: Hovering', skillName);
        clearTimeout(collapseTimer);
        clearTimeout(expandTimer);
        
        expandTimer = setTimeout(() => {
            showGif(container, gifUrl, skillName);
        }, CONFIG.expandDelay);
    }

    function showGif(container, gifUrl, skillName) {
        console.log('Dynamic GIF Displayer: Showing GIF for', skillName);
        
        const displayArea = container.querySelector('.' + CONFIG.displayClass);
        if (!displayArea) return;
        
        const gifSize = sanitizeGifSize(container.getAttribute('data-gif-size'));
        
        if (!container.classList.contains('expanded')) {
            container.classList.add('expanded');
            console.log('Dynamic GIF Displayer: Expanded container');
        }
        
        if (currentGif !== gifUrl) {
            const imgContainer = displayArea.querySelector('.gif-image-container');
            const caption = displayArea.querySelector('.gif-caption');
            
            if (imgContainer) {
                const placeholder = imgContainer.querySelector('.gif-placeholder');
                if (placeholder) {
                    placeholder.remove();
                }
                
                imgContainer.style.height = gifSize + 'px';
                imgContainer.style.minHeight = gifSize + 'px';
                
                const gifFilename = gifUrl.split('/').pop();
                if (gifFilename.toLowerCase() === 'blank' || gifFilename.toLowerCase() === 'blank.gif') {
                    const placeholderDiv = createTextElement('div', 'gif-placeholder', 
                        'This node does not require a GIF due to its simplicity.');
                    imgContainer.innerHTML = '';
                    imgContainer.appendChild(placeholderDiv);
                    imgContainer.classList.remove('loading');
                } else {
                    imgContainer.classList.add('loading');
                    
                    const img = document.createElement('img');
                    img.src = gifUrl;
                    img.alt = skillName;
                    img.style.maxHeight = gifSize + 'px';
                    
                    img.onload = () => {
                        imgContainer.innerHTML = '';
                        imgContainer.appendChild(img);
                        imgContainer.classList.remove('loading');
                        console.log('Dynamic GIF Displayer: GIF loaded successfully');
                    };
                    
                    img.onerror = () => {
                        const errorDiv = createTextElement('div', 'gif-error', 
                            'GIF not found: ' + gifUrl);
                        imgContainer.innerHTML = '';
                        imgContainer.appendChild(errorDiv);
                        imgContainer.classList.remove('loading');
                        console.error('Dynamic GIF Displayer: Failed to load GIF', gifUrl);
                    };
                }
            }
            
            if (caption) {
                caption.textContent = skillName;
                caption.style.display = 'block';
            }
            
            currentGif = gifUrl;
        }
    }
    
    function scheduleCollapse(container) {
        clearTimeout(collapseTimer);
        
        collapseTimer = setTimeout(() => {
            container.classList.remove('expanded');
            
            const displayArea = container.querySelector('.' + CONFIG.displayClass);
            if (displayArea) {
                const imgContainer = displayArea.querySelector('.gif-image-container');
                const caption = displayArea.querySelector('.gif-caption');
                
                if (imgContainer) {
                    const placeholderDiv = createTextElement('div', 'gif-placeholder', 
                        'Hover over a skill node to see its demonstration');
                    imgContainer.innerHTML = '';
                    imgContainer.appendChild(placeholderDiv);
                    imgContainer.style.height = '';
                    imgContainer.style.minHeight = '';
                }
                
                if (caption) {
                    caption.textContent = '';
                    caption.style.display = 'none';
                }
            }
            
            currentGif = null;
            console.log('Dynamic GIF Displayer: Collapsed container and cleared content');
        }, CONFIG.collapseDelay);
    }
    
    window.toggleGifDisplay = function(containerId) {
        console.log('Dynamic GIF Displayer: Toggle clicked for', containerId);
        
        if (typeof containerId !== 'string' || !containerId.match(/^[a-zA-Z0-9_-]+$/)) {
            console.error('Dynamic GIF Displayer: Invalid container ID');
            return;
        }
        
        const container = document.getElementById(containerId);
        if (!container) {
            console.error('Dynamic GIF Displayer: Container not found', containerId);
            return;
        }
        
        clearTimeout(collapseTimer);
        
        if (container.style.display === 'none') {
            container.style.display = 'block';
        } else {
            container.style.display = 'none';
        }
        
        if (container.style.display === 'none') {
            const displayArea = container.querySelector('.' + CONFIG.displayClass);
            if (displayArea) {
                const imgContainer = displayArea.querySelector('.gif-image-container');
                const caption = displayArea.querySelector('.gif-caption');
                
                if (imgContainer) {
                    const placeholderDiv = createTextElement('div', 'gif-placeholder', 
                        'Hover over a skill node to see its demonstration');
                    imgContainer.innerHTML = '';
                    imgContainer.appendChild(placeholderDiv);
                    imgContainer.style.height = '';
                    imgContainer.style.minHeight = '';
                }
                
                if (caption) {
                    caption.textContent = '';
                    caption.style.display = 'none';
                }
            }
            
            container.classList.remove('expanded');
            currentGif = null;
        }
    };

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }
    
    window.addEventListener('load', init);
    
    if (typeof mw !== 'undefined' && mw.hook) {
        mw.hook('wikipage.content').add(init);
    }
    
    const observer = new MutationObserver(function(mutations) {
        let shouldReinit = false;
        mutations.forEach(function(mutation) {
            if (mutation.addedNodes.length) {
                mutation.addedNodes.forEach(function(node) {
                    if (node.nodeType === 1 && (
                        node.classList && node.classList.contains('advanced-tooltip') ||
                        node.querySelector && node.querySelector('.advanced-tooltip')
                    )) {
                        shouldReinit = true;
                    }
                });
            }
        });
        if (shouldReinit) {
            console.log('Dynamic GIF Displayer: Content changed, reinitializing...');
            setTimeout(init, 100);
        }
    });
    
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });
    
    console.log('Dynamic GIF Displayer: Script loaded');
})();