MediaWiki:Common.js

From Survival Servers
Revision as of 20:24, 20 July 2026 by Ryan (talk | contribs) (Skin v2: scroll-spy TOC, terminal frames + copy, callout promotion, lightbox, responsive viewport)
Jump to navigation Jump 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)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/**
 * SurvivalServers Wiki - Game Server Banner System v5.4
 * Dark theme with gold accents matching main site design
 * Includes affiliate tracking: trckaff=3881, trckit=WIKI<PageName>
 * Fixed dbnames: ark (ASA), citadel, empyriongalacticsurvival, rune2
 * Smart linking: order form if pricing exists, service page if not
 */
(function() {
    'use strict';

    var TRACK_AFF_ID = '3881';
    var MAX_TRCKIT_LENGTH = 41;
    var API_URL = 'https://www.survivalservers.com/includes/wiki_pricing_api.php';
    var LOGO_URL = 'https://www.survivalservers.com/themes/epona/images/logo.png';
    var GAME_ICON_BASE = 'https://www.survivalservers.com/themes/epona/images/sspanel/game-server-icons-sm/';

    // SVG Icons (inline so no external library needed)
    var ICONS = {
        bolt: '<svg style="width:14px;height:14px;margin-right:5px;vertical-align:middle;" viewBox="0 0 320 512" fill="rgb(219,155,21)"><path d="M296 160H180.6l42.6-129.8C227.2 15 215.7 0 200 0H56C44 0 33.8 8.9 32.2 20.8l-32 240C-1.7 275.2 9.5 288 24 288h118.7L96.6 482.5c-3.6 15.2 8 29.5 23.3 29.5 8.4 0 16.4-4.4 20.8-12l176-304c9.3-15.9-2.2-36-20.7-36z"/></svg>',
        sliders: '<svg style="width:14px;height:14px;margin-right:5px;vertical-align:middle;" viewBox="0 0 512 512" fill="rgb(219,155,21)"><path d="M496 384H160v-16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v16H16c-8.8 0-16 7.2-16 16v32c0 8.8 7.2 16 16 16h80v16c0 8.8 7.2 16 16 16h32c8.8 0 16-7.2 16-16v-16h336c8.8 0 16-7.2 16-16v-32c0-8.8-7.2-16-16-16zm0-160h-80v-16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v16H16c-8.8 0-16 7.2-16 16v32c0 8.8 7.2 16 16 16h336v16c0 8.8 7.2 16 16 16h32c8.8 0 16-7.2 16-16v-16h80c8.8 0 16-7.2 16-16v-32c0-8.8-7.2-16-16-16zm0-160H288V48c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v16H16C7.2 64 0 71.2 0 80v32c0 8.8 7.2 16 16 16h208v16c0 8.8 7.2 16 16 16h32c8.8 0 16-7.2 16-16v-16h208c8.8 0 16-7.2 16-16V80c0-8.8-7.2-16-16-16z"/></svg>',
        rocket: '<svg style="width:14px;height:14px;margin-right:5px;vertical-align:middle;" viewBox="0 0 512 512" fill="rgb(219,155,21)"><path d="M505.12019,19.09375c-1.18945-5.53125-6.65819-11-12.207-12.1875C460.716,0,435.507,0,410.40747,0,307.17523,0,245.26909,55.20312,199.05238,128H94.83772c-16.34763,0-31.08301,9.59375-37.69531,24.5L3.14257,262.5C-.87883,270.625-1.03822,280.28125,2.67739,288.5s11.31445,14.5,19.69531,14.5H131.0701L93.43994,340.65625c-15.64063,15.625-15.64063,40.96875,0,56.59375,15.6289,15.625,40.97656,15.625,56.60547,0L187.92919,360H256v128c0,17.67188,14.32617,32,32,32s32-14.32812,32-32V303.0625c74.38477-46.03125,128-108.75,128-212.09375C448,70.59375,447.84058,50.1875,505.12019,19.09375Z"/></svg>',
        cart: '<svg style="width:14px;height:14px;margin-right:6px;vertical-align:middle;" viewBox="0 0 576 512" fill="currentColor"><path d="M528.12 301.319l47.273-208C578.806 78.301 567.391 64 551.99 64H159.208l-9.166-44.81C147.758 8.021 137.93 0 126.529 0H24C10.745 0 0 10.745 0 24v16c0 13.255 10.745 24 24 24h69.883l70.248 343.435C147.325 417.1 136 435.222 136 456c0 30.928 25.072 56 56 56s56-25.072 56-56c0-15.674-6.447-29.835-16.824-40h209.647C430.447 426.165 424 440.326 424 456c0 30.928 25.072 56 56 56s56-25.072 56-56c0-22.172-12.888-41.332-31.579-50.405l5.517-24.276c3.413-15.018-8.002-29.319-23.403-29.319H218.117l-6.545-32h293.145c11.206 0 20.92-7.754 23.403-18.681z"/></svg>',
        gamepad: '<svg style="width:16px;height:16px;margin-right:6px;vertical-align:middle;" viewBox="0 0 640 512" fill="currentColor"><path d="M480 96H160C71.6 96 0 167.6 0 256s71.6 160 160 160c44.8 0 85.2-18.4 114.2-48h91.5c29 29.6 69.5 48 114.2 48 88.4 0 160-71.6 160-160S568.4 96 480 96zM256 276c0 6.6-5.4 12-12 12h-52v52c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-52H76c-6.6 0-12-5.4-12-12v-40c0-6.6 5.4-12 12-12h52v-52c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v52h52c6.6 0 12 5.4 12 12v40zm184 68c-26.5 0-48-21.5-48-48s21.5-48 48-48 48 21.5 48 48-21.5 48-48 48zm80-80c-26.5 0-48-21.5-48-48s21.5-48 48-48 48 21.5 48 48-21.5 48-48 48z"/></svg>'
    };

    var gameConfig = {
        // 7 Days to Die - including common abbreviation "7D2D"
        '7daystodie': { name: '7 Days to Die', slug: '7_days_to_die', dbname: 'sevendays' },
        '7days': { name: '7 Days to Die', slug: '7_days_to_die', dbname: 'sevendays' },
        '7d2d': { name: '7 Days to Die', slug: '7_days_to_die', dbname: 'sevendays' },

        // ARK: Survival Evolved - including PS4 variants and colon variations
        'ark': { name: 'ARK: Survival Evolved', slug: 'ark_survival_evolved', dbname: 'ark' },
        'ark:': { name: 'ARK: Survival Evolved', slug: 'ark_survival_evolved', dbname: 'ark' },
        'ark ps4': { name: 'ARK: Survival Evolved', slug: 'ark_survival_evolved', dbname: 'ark' },
        'arkps4': { name: 'ARK: Survival Evolved', slug: 'ark_survival_evolved', dbname: 'ark' },
        'ark: survival evolved': { name: 'ARK: Survival Evolved', slug: 'ark_survival_evolved', dbname: 'ark' },
        'ark:survival evolved': { name: 'ARK: Survival Evolved', slug: 'ark_survival_evolved', dbname: 'ark' },
        'arkon': { name: 'ARK: Survival Evolved', slug: 'ark_survival_evolved', dbname: 'ark' },
        'beacon': { name: 'ARK: Survival Evolved', slug: 'ark_survival_evolved', dbname: 'ark' },

        // ARK: Survival Ascended
        'arksurvivalascended': { name: 'ARK: Survival Ascended', slug: 'ark_survival_ascended', dbname: 'ark' },
        'asa': { name: 'ARK: Survival Ascended', slug: 'ark_survival_ascended', dbname: 'ark' },

        // Arma series
        'arma': { name: 'Arma 3', slug: 'arma3', dbname: 'arma3' },
        'arma 2': { name: 'Arma 3', slug: 'arma3', dbname: 'arma3' },
        'arma 3': { name: 'Arma 3', slug: 'arma3', dbname: 'arma3' },
        'arma3': { name: 'Arma 3', slug: 'arma3', dbname: 'arma3' },
        'arma reforger': { name: 'Arma Reforger', slug: 'arma_reforger', dbname: 'armareforger' },
        'epoch': { name: 'Arma 3', slug: 'arma3', dbname: 'arma3' },
        'exile': { name: 'Arma 3', slug: 'arma3', dbname: 'arma3' },
        'altis': { name: 'Arma 3', slug: 'arma3', dbname: 'arma3' },
        'wasteland': { name: 'Arma 3', slug: 'arma3', dbname: 'arma3' },
        'overpoch': { name: 'Arma 3', slug: 'arma3', dbname: 'arma3' },
        'pbo': { name: 'Arma 3', slug: 'arma3', dbname: 'arma3' },
        'infistar': { name: 'Arma 3', slug: 'arma3', dbname: 'arma3' },

        // Atlas
        'atlas': { name: 'Atlas', slug: 'atlas', dbname: 'atlas' },

        // Avorion
        'avorion': { name: 'Avorion', slug: 'avorion', dbname: 'avorion' },

        // Barotrauma
        'barotrauma': { name: 'Barotrauma', slug: 'barotrauma', dbname: 'barotrauma' },
        'barotrauam': { name: 'Barotrauma', slug: 'barotrauma', dbname: 'barotrauma' },

        // Battalion 1944
        'battalion': { name: 'Battalion 1944', slug: 'battalion_1944', dbname: 'battalion1944' },
        'battalion 1944': { name: 'Battalion 1944', slug: 'battalion_1944', dbname: 'battalion1944' },

        // Brickadia
        'brickadia': { name: 'Brickadia', slug: 'brickadia', dbname: 'brickadia' },

        // Citadel: Forged With Fire
        'citadel': { name: 'Citadel: Forged With Fire', slug: 'citadel_forged_with_fire', dbname: 'citadel' },

        // Conan Exiles
        'conan': { name: 'Conan Exiles', slug: 'conan_exiles', dbname: 'conanexiles' },
        'conanexiles': { name: 'Conan Exiles', slug: 'conan_exiles', dbname: 'conanexiles' },
        'conan exiles': { name: 'Conan Exiles', slug: 'conan_exiles', dbname: 'conanexiles' },

        // Conan Exiles Enhanced (UE5 remaster — separate game from Legacy)
        'conan exiles enhanced': { name: 'Conan Exiles Enhanced', slug: 'conan_exiles_enhanced', dbname: 'conanexilesenhanced' },
        'conanexilesenhanced': { name: 'Conan Exiles Enhanced', slug: 'conan_exiles_enhanced', dbname: 'conanexilesenhanced' },
        'conan enhanced': { name: 'Conan Exiles Enhanced', slug: 'conan_exiles_enhanced', dbname: 'conanexilesenhanced' },

        // Core Keeper
        'corekeeper': { name: 'Core Keeper', slug: 'core_keeper', dbname: 'corekeeper' },
        'core keeper': { name: 'Core Keeper', slug: 'core_keeper', dbname: 'corekeeper' },

        // Counter-Strike 2 / CS2 / CSGO
        'csgo': { name: 'CS2', slug: 'counter_strike_2', dbname: 'csgo' },
        'cs2': { name: 'CS2', slug: 'counter_strike_2', dbname: 'csgo' },
        'counterstrike': { name: 'CS2', slug: 'counter_strike_2', dbname: 'csgo' },
        'counter strike': { name: 'CS2', slug: 'counter_strike_2', dbname: 'csgo' },
        'counter-strike': { name: 'CS2', slug: 'counter_strike_2', dbname: 'csgo' },

        // Dark and Light
        'dark and light': { name: 'Dark and Light', slug: 'dark_and_light', dbname: 'darkandlight' },
        'darkandlight': { name: 'Dark and Light', slug: 'dark_and_light', dbname: 'darkandlight' },

        // Day of Dragons
        'day of dragons': { name: 'Day of Dragons', slug: 'day_of_dragons', dbname: 'dayofdragons' },
        'dayofdragons': { name: 'Day of Dragons', slug: 'day_of_dragons', dbname: 'dayofdragons' },

        // DayZ
        'dayz': { name: 'DayZ', slug: 'dayz', dbname: 'dayz' },

        // Dead Matter
        'deadmatter': { name: 'Dead Matter', slug: 'dead_matter', dbname: 'deadmatter' },
        'dead matter': { name: 'Dead Matter', slug: 'dead_matter', dbname: 'deadmatter' },

        // Don't Starve Together
        'dontstarve': { name: "Don't Starve Together", slug: 'dont_starve_together', dbname: 'dontstarvetogether' },
        "don't starve": { name: "Don't Starve Together", slug: 'dont_starve_together', dbname: 'dontstarvetogether' },

        // Eco
        'eco': { name: 'Eco', slug: 'eco', dbname: 'eco' },

        // Empyrion
        'empyrion': { name: 'Empyrion', slug: 'empyrion_galactic_survival', dbname: 'empyriongalacticsurvival' },

        // Enshrouded
        'enshrouded': { name: 'Enshrouded', slug: 'enshrouded', dbname: 'enshrouded' },

        // Factorio
        'factorio': { name: 'Factorio', slug: 'factorio', dbname: 'factorio' },

        // FiveM / RedM
        'fivem': { name: 'FiveM', slug: 'grand_theft_auto_5', dbname: 'fivem' },
        'redm': { name: 'RedM', slug: 'red_dead_redemption', dbname: 'redm' },

        // Foundry
        'foundry': { name: 'Foundry', slug: 'foundry', dbname: 'foundry' },

        // Frozen Flame
        'frozen flame': { name: 'Frozen Flame', slug: 'frozen_flame', dbname: 'frozenflame' },
        'frozenflame': { name: 'Frozen Flame', slug: 'frozen_flame', dbname: 'frozenflame' },

        // Holdfast
        'holdfast': { name: 'Holdfast: Nations At War', slug: 'holdfast', dbname: 'holdfast' },

        // Hurtworld
        'hurtworld': { name: 'Hurtworld', slug: 'hurtworld', dbname: 'hurtworld' },

        // Hytale
        'hytale': { name: 'Hytale', slug: 'hytale', dbname: 'hytale' },

        // Icarus
        'icarus': { name: 'Icarus', slug: 'icarus', dbname: 'icarus' },

        // Last Oasis
        'last oasis': { name: 'Last Oasis', slug: 'last_oasis', dbname: 'lastoasis' },
        'lastoasis': { name: 'Last Oasis', slug: 'last_oasis', dbname: 'lastoasis' },

        // Left 4 Dead 2
        'left4dead': { name: 'Left 4 Dead 2', slug: 'left_4_dead_2', dbname: 'left4dead2' },
        'l4d2': { name: 'Left 4 Dead 2', slug: 'left_4_dead_2', dbname: 'left4dead2' },

        // Minecraft - including mods and tools
        'minecraft': { name: 'Minecraft', slug: 'minecraft', dbname: 'minecraft' },
        'mcrcon': { name: 'Minecraft', slug: 'minecraft', dbname: 'minecraft' },
        'craftbukkit': { name: 'Minecraft', slug: 'minecraft', dbname: 'minecraft' },
        'pixelmon': { name: 'Minecraft', slug: 'minecraft', dbname: 'minecraft' },

        // Miscreated
        'miscreated': { name: 'Miscreated', slug: 'miscreated', dbname: 'miscreated' },

        // Mordhau
        'mordhau': { name: 'Mordhau', slug: 'mordhau', dbname: 'mordhau' },

        // Mount & Blade 2: Bannerlord
        'bannerlord': { name: 'Mount & Blade 2: Bannerlord', slug: 'mount_and_blade_2_bannerlord', dbname: 'bannerlord' },

        // Myth of Empires
        'myth of empires': { name: 'Myth of Empires', slug: 'myth_of_empires', dbname: 'mythofempires' },
        'mythofempires': { name: 'Myth of Empires', slug: 'myth_of_empires', dbname: 'mythofempires' },

        // Nightingale
        'nightingale': { name: 'Nightingale', slug: 'nightingale', dbname: 'nightingale' },

        // No One Survived
        'no one survived': { name: 'No One Survived', slug: 'no_one_survived', dbname: 'noonesurvived' },
        'noonesurvived': { name: 'No One Survived', slug: 'no_one_survived', dbname: 'noonesurvived' },

        // Palworld
        'palworld': { name: 'Palworld', slug: 'palworld', dbname: 'palworld' },

        // Path of Titans
        'path of titans': { name: 'Path of Titans', slug: 'path_of_titans', dbname: 'pathoftitans' },
        'pathoftitans': { name: 'Path of Titans', slug: 'path_of_titans', dbname: 'pathoftitans' },

        // PixARK
        'pixark': { name: 'PixARK', slug: 'pixark', dbname: 'pixark' },

        // Project Zomboid
        'projectzomboid': { name: 'Project Zomboid', slug: 'project_zomboid', dbname: 'projectzomboid' },
        'zomboid': { name: 'Project Zomboid', slug: 'project_zomboid', dbname: 'projectzomboid' },
        'project zomboid': { name: 'Project Zomboid', slug: 'project_zomboid', dbname: 'projectzomboid' },

        // Rend
        'rend': { name: 'Rend', slug: 'rend', dbname: 'rend' },

        // Renown
        'renown': { name: 'Renown', slug: 'renown', dbname: 'renown' },

        // Rust
        'rust': { name: 'Rust', slug: 'rust', dbname: 'rust' },
        'rusty': { name: 'Rust', slug: 'rust', dbname: 'rust' },
        'oxide': { name: 'Rust', slug: 'rust', dbname: 'rust' },

        // Satisfactory
        'satisfactory': { name: 'Satisfactory', slug: 'satisfactory', dbname: 'satisfactory' },

        // SCUM
        'scum': { name: 'SCUM', slug: 'scum', dbname: 'scum' },

        // Sons of the Forest
        'sonsoftheforest': { name: 'Sons of the Forest', slug: 'sons_of_the_forest', dbname: 'sonsoftheforest' },
        'sons of the forest': { name: 'Sons of the Forest', slug: 'sons_of_the_forest', dbname: 'sonsoftheforest' },
        'sons of forest': { name: 'Sons of the Forest', slug: 'sons_of_the_forest', dbname: 'sonsoftheforest' },

        // Soulmask
        'soulmask': { name: 'Soulmask', slug: 'soulmask', dbname: 'soulmask' },

        // Space Engineers
        'spaceengineers': { name: 'Space Engineers', slug: 'space_engineers', dbname: 'spaceengineers' },
        'space engineers': { name: 'Space Engineers', slug: 'space_engineers', dbname: 'spaceengineers' },

        // Squad
        'squad': { name: 'Squad', slug: 'squad', dbname: 'squad' },

        // Starbound
        'starbound': { name: 'Starbound', slug: 'starbound', dbname: 'starbound' },

        // Stationeers
        'stationeers': { name: 'Stationeers', slug: 'stationeers', dbname: 'stationeers' },

        // StarRupture
        'starrupture': { name: 'StarRupture', slug: 'starrupture', dbname: 'starrupture' },

        // Terraria
        'terraria': { name: 'Terraria', slug: 'terraria', dbname: 'terraria' },

        // The Forest
        'theforest': { name: 'The Forest', slug: 'the_forest', dbname: 'theforest' },
        'forest': { name: 'The Forest', slug: 'the_forest', dbname: 'theforest' },
        'the forest': { name: 'The Forest', slug: 'the_forest', dbname: 'theforest' },

        // The Front
        'the front': { name: 'The Front', slug: 'the_front', dbname: 'thefront' },
        'thefront': { name: 'The Front', slug: 'the_front', dbname: 'thefront' },

        // The Isle
        'theisle': { name: 'The Isle', slug: 'the_isle', dbname: 'theisle' },
        'isle': { name: 'The Isle', slug: 'the_isle', dbname: 'theisle' },
        'the isle': { name: 'The Isle', slug: 'the_isle', dbname: 'theisle' },

        // Unturned
        'unturned': { name: 'Unturned', slug: 'unturned', dbname: 'unturned' },

        // V Rising
        'v rising': { name: 'V Rising', slug: 'v_rising', dbname: 'vrising' },
        'vrising': { name: 'V Rising', slug: 'v_rising', dbname: 'vrising' },

        // Valheim
        'valheim': { name: 'Valheim', slug: 'valheim', dbname: 'valheim' },
        'valheim plus': { name: 'Valheim', slug: 'valheim', dbname: 'valheim' },
        'valheimplus': { name: 'Valheim', slug: 'valheim', dbname: 'valheim' },

        // Vein
        'vein': { name: 'Vein', slug: 'vein', dbname: 'vein' },

        // Ylands
        'ylands': { name: 'Ylands', slug: 'ylands', dbname: 'ylands' },

        // Abiotic Factor
        'abiotic': { name: 'Abiotic Factor', slug: 'abiotic_factor', dbname: 'abioticfactor' },
        'abiotic factor': { name: 'Abiotic Factor', slug: 'abiotic_factor', dbname: 'abioticfactor' },

        // Aloft
        'aloft': { name: 'Aloft', slug: 'aloft', dbname: 'aloft' },

        // Assetto Corsa
        'assettocorsa': { name: 'Assetto Corsa', slug: 'assetto_corsa', dbname: 'assettocorsa' },
        'assetto': { name: 'Assetto Corsa', slug: 'assetto_corsa', dbname: 'assettocorsa' },

        // ASKA
        'aska': { name: 'ASKA', slug: 'aska', dbname: 'aska' },

        // Cube World
        'cube world': { name: 'Cube World', slug: 'cube_world', dbname: 'cubeworld' },
        'cubeworld': { name: 'Cube World', slug: 'cube_world', dbname: 'cubeworld' },

        // Rune / Rune 2
        'rune': { name: 'Rune: Ragnarok', slug: 'rune_ragnarok', dbname: 'rune2' },
        'rune 2': { name: 'Rune: Ragnarok', slug: 'rune_ragnarok', dbname: 'rune2' },

        // Subnautica
        'subnautica': { name: 'Subnautica', slug: 'subnautica', dbname: 'subnautica' },

        // Torch (Rust-related)
        'torch': { name: 'Rust', slug: 'rust', dbname: 'rust' },

        // Windrose
        'windrose': { name: 'Windrose', slug: 'windrose', dbname: 'windrose' }
    };

    function getPageName() {
        var urlParams = new URLSearchParams(window.location.search);
        var title = urlParams.get('title');
        if (!title) {
            var path = window.location.pathname;
            var match = path.match(/\/wiki\/(.+)$/);
            if (match) title = decodeURIComponent(match[1]);
        }
        if (!title) {
            var heading = document.getElementById('firstHeading');
            if (heading) title = heading.textContent;
        }
        if (title) {
            title = title.replace(/[^a-zA-Z0-9]/g, '_').replace(/_+/g, '_').substring(0, MAX_TRCKIT_LENGTH);
        }
        return title || 'Unknown';
    }

    function buildTrackingUrl(baseUrl, pageName) {
        var separator = baseUrl.indexOf('?') === -1 ? '?' : '&';
        return baseUrl + separator + 'trckaff=' + TRACK_AFF_ID + '&trckit=WIKI' + pageName;
    }

    function detectGame() {
        var pageTitle = document.title.toLowerCase();
        var bodyContent = document.getElementById('bodyContent');

        var manualGame = document.querySelector('[data-ss-game]');
        if (manualGame) return manualGame.getAttribute('data-ss-game').toLowerCase();

        var content = bodyContent ? bodyContent.innerHTML : '';
        var markerMatch = content.match(/<!--\s*SSGAME:\s*(\w+)\s*-->/i);
        if (markerMatch) return markerMatch[1].toLowerCase();

        var keywords = Object.keys(gameConfig).sort(function(a, b) { return b.length - a.length; });
        for (var i = 0; i < keywords.length; i++) {
            if (pageTitle.indexOf(keywords[i]) !== -1) return keywords[i];
        }
        return null;
    }

    function fetchPricing(gameSlug, callback) {
        var xhr = new XMLHttpRequest();
        xhr.open('GET', API_URL + '?game=' + encodeURIComponent(gameSlug), true);
        xhr.onreadystatechange = function() {
            if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                    try {
                        var data = JSON.parse(xhr.responseText);
                        callback(data);
                    } catch (e) {
                        callback(null);
                    }
                } else {
                    callback(null);
                }
            }
        };
        xhr.send();
    }

    function createGameBanner(gameKey, pageName, pricingData) {
        var game = gameConfig[gameKey];
        if (!game) return null;
        // If pricing data exists, link to order form; otherwise link to service page
        var orderUrl = pricingData && pricingData.lowestPrice
            ? 'https://www.survivalservers.com/sspanel/?game=' + game.dbname
            : 'https://www.survivalservers.com/services/game_servers/' + game.slug + '/';
        var trackingUrl = buildTrackingUrl(orderUrl, pageName);
        var gameIconUrl = GAME_ICON_BASE + game.dbname + '.png';

        var priceHtml = '';
        if (pricingData && pricingData.lowestPrice) {
            if (pricingData.discount && pricingData.discountedPrice && pricingData.coupon) {
                priceHtml = '<span style="display: inline-flex; align-items: center; vertical-align: middle;">' +
                    '<span style="color: rgba(255,255,255,0.7); margin: 0 12px;">|</span>' +
                    '<span style="background: #00aa55; color: #fff; padding: 2px 8px; border-radius: 3px; font-size: 12px; font-weight: 700; display: inline-flex; align-items: center;">Use code ' + pricingData.coupon + ' for ' + pricingData.discount + '% OFF</span>' +
                    '<span style="color: rgba(255,255,255,0.5); margin: 0 8px;"></span>' +
                    '<span style="color: #888; text-decoration: line-through; font-size: 13px; display: inline-flex; align-items: center;">$' + pricingData.lowestPrice + '</span>' +
                    '<span style="color: #00ff88; font-weight: 700; margin-left: 6px; display: inline-flex; align-items: center;">$' + pricingData.discountedPrice + '/mo</span>' +
                '</span>';
            } else {
                priceHtml = '<span style="display: inline-flex; align-items: center; vertical-align: middle;">' +
                    '<span style="color: rgba(255,255,255,0.7); margin: 0 12px;">|</span>' +
                    '<span style="color: #00ff88; font-weight: 700; display: inline-flex; align-items: center;">From $' + pricingData.lowestPrice + '/mo</span>' +
                '</span>';
            }
        }

        var banner = document.createElement('div');
        banner.id = 'ss-game-banner';
        banner.innerHTML = '<div style="background: #1a1a1a; border-radius: 6px; padding: 0; margin: 0 0 20px 0; box-shadow: 0 2px 10px rgba(0,0,0,0.5); overflow: hidden; border: 2px solid rgb(219, 155, 21);">' +
            '<div style="padding: 16px 25px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 15px;">' +
                '<div style="display: flex; align-items: center; gap: 18px; flex: 1; min-width: 280px;">' +
                    '<a href="' + buildTrackingUrl('https://www.survivalservers.com/', pageName) + '" style="flex-shrink: 0; display: flex; align-items: center;"><img src="' + LOGO_URL + '" alt="SurvivalServers" style="height: 32px; width: auto; vertical-align: middle;"></a>' +
                    '<div style="height: 28px; width: 1px; background: rgba(255,255,255,0.2);"></div>' +
                    '<div style="display: flex; align-items: center; gap: 10px;">' +
                        '<img src="' + gameIconUrl + '" alt="" style="width: 28px; height: 28px; border-radius: 4px; vertical-align: middle;" onerror="this.style.display=\'none\'">' +
                        '<span style="color: rgb(219, 155, 21); font-weight: 600; font-size: 15px; display: inline-flex; align-items: center;">' + game.name + ' Server Hosting</span>' +
                    '</div>' +
                    priceHtml +
                '</div>' +
                '<div style="display: flex; align-items: center; gap: 20px;">' +
                    '<div style="color: rgba(255,255,255,0.8); font-size: 13px; display: flex; align-items: center; gap: 12px;">' +
                        '<span style="display: inline-flex; align-items: center;">' + ICONS.bolt + 'High Performance</span>' +
                        '<span style="color: rgba(255,255,255,0.4);">&#8226;</span>' +
                        '<span style="display: inline-flex; align-items: center;">' + ICONS.sliders + 'Custom Control Panel</span>' +
                        '<span style="color: rgba(255,255,255,0.4);">&#8226;</span>' +
                        '<span style="display: inline-flex; align-items: center;">' + ICONS.rocket + 'Instant Setup</span>' +
                    '</div>' +
                    '<a href="' + trackingUrl + '" style="background: rgb(219, 155, 21); color: #1a1a1a; padding: 10px 28px; border-radius: 4px; text-decoration: none; font-weight: 700; font-size: 14px; display: inline-flex; align-items: center; gap: 8px; transition: all 0.2s ease; white-space: nowrap;" onmouseover="this.style.background=\'rgb(239, 175, 41)\';this.style.transform=\'translateY(-1px)\';" onmouseout="this.style.background=\'rgb(219, 155, 21)\';this.style.transform=\'translateY(0)\';">' +
                        ICONS.cart + 'Order Now' +
                    '</a>' +
                '</div>' +
            '</div>' +
        '</div>';
        return banner;
    }

    function createGenericBanner(pageName, pricingData) {
        var trackingUrl = buildTrackingUrl('https://www.survivalservers.com/', pageName);

        var couponHtml = '';
        if (pricingData && pricingData.discount && pricingData.coupon) {
            couponHtml = '<span style="display: inline-flex; align-items: center; vertical-align: middle;">' +
                '<span style="color: rgba(255,255,255,0.7); margin: 0 12px;">|</span>' +
                '<span style="background: #00aa55; color: #fff; padding: 2px 8px; border-radius: 3px; font-size: 12px; font-weight: 700; display: inline-flex; align-items: center;">Use code ' + pricingData.coupon + ' for ' + pricingData.discount + '% OFF</span>' +
            '</span>';
        }

        var banner = document.createElement('div');
        banner.id = 'ss-game-banner';
        banner.innerHTML = '<div style="background: #1a1a1a; border-radius: 6px; padding: 0; margin: 0 0 20px 0; box-shadow: 0 2px 10px rgba(0,0,0,0.5); overflow: hidden; border: 2px solid rgb(219, 155, 21);">' +
            '<div style="padding: 16px 25px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 15px;">' +
                '<div style="display: flex; align-items: center; gap: 18px; flex: 1; min-width: 280px;">' +
                    '<a href="' + trackingUrl + '" style="flex-shrink: 0; display: flex; align-items: center;"><img src="' + LOGO_URL + '" alt="SurvivalServers" style="height: 32px; width: auto; vertical-align: middle;"></a>' +
                    '<div style="height: 28px; width: 1px; background: rgba(255,255,255,0.2);"></div>' +
                    '<span style="color: rgb(219, 155, 21); font-weight: 600; font-size: 15px; display: inline-flex; align-items: center;">Premium Game Server Hosting</span>' +
                    '<span style="color: rgba(255,255,255,0.7); margin: 0 8px; display: inline-flex; align-items: center;">|</span>' +
                    '<span style="color: rgba(255,255,255,0.9); font-size: 14px; display: inline-flex; align-items: center;">100+ Games Available</span>' +
                    couponHtml +
                '</div>' +
                '<div style="display: flex; align-items: center; gap: 20px;">' +
                    '<div style="color: rgba(255,255,255,0.8); font-size: 13px; display: flex; align-items: center; gap: 12px;">' +
                        '<span style="display: inline-flex; align-items: center;">' + ICONS.bolt + 'High Performance</span>' +
                        '<span style="color: rgba(255,255,255,0.4);">&#8226;</span>' +
                        '<span style="display: inline-flex; align-items: center;">' + ICONS.sliders + 'Custom Control Panel</span>' +
                        '<span style="color: rgba(255,255,255,0.4);">&#8226;</span>' +
                        '<span style="display: inline-flex; align-items: center;">' + ICONS.rocket + 'Instant Setup</span>' +
                    '</div>' +
                    '<a href="' + trackingUrl + '" style="background: rgb(219, 155, 21); color: #1a1a1a; padding: 10px 28px; border-radius: 4px; text-decoration: none; font-weight: 700; font-size: 14px; display: inline-flex; align-items: center; gap: 8px; transition: all 0.2s ease; white-space: nowrap;" onmouseover="this.style.background=\'rgb(239, 175, 41)\';this.style.transform=\'translateY(-1px)\';" onmouseout="this.style.background=\'rgb(219, 155, 21)\';this.style.transform=\'translateY(0)\';">' +
                        ICONS.gamepad + 'Browse Games' +
                    '</a>' +
                '</div>' +
            '</div>' +
        '</div>';
        return banner;
    }

    function insertBanner(banner) {
        if (!banner) return;
        var contentDiv = document.getElementById('bodyContent');
        if (contentDiv) contentDiv.insertBefore(banner, contentDiv.firstChild);
    }

    function updateExistingLinks(pageName) {
        // Find all links to survivalservers.com and add/fix tracking params
        var links = document.querySelectorAll('a[href*="survivalservers.com"]');
        for (var i = 0; i < links.length; i++) {
            var link = links[i];
            var href = link.getAttribute('href');

            // Skip if it's our banner (we already add tracking there)
            if (link.closest('#ss-game-banner')) continue;

            // Check if link has incomplete trckit=WIKI (without page name)
            // Match trckit=WIKI at end of string or followed by & or nothing after
            if (href.match(/trckit=WIKI(&|$)/)) {
                // Replace incomplete trckit with full page name
                href = href.replace(/trckit=WIKI(&|$)/, 'trckit=WIKI' + pageName + '$1');
                link.setAttribute('href', href);
                continue;
            }

            // Skip if already has complete tracking params
            if (href.indexOf('trckaff=') !== -1) continue;

            // Add tracking params
            var separator = href.indexOf('?') === -1 ? '?' : '&';
            link.setAttribute('href', href + separator + 'trckaff=' + TRACK_AFF_ID + '&trckit=WIKI' + pageName);
        }
    }

    function init() {
        var pageTitle = document.title;
        if (pageTitle.indexOf('Main Page') !== -1) return;
        if (window.location.href.indexOf('Special:') !== -1) return;

        var pageName = getPageName();
        var gameKey = detectGame();
        var game = gameKey ? gameConfig[gameKey] : null;

        // Update existing links on the page with tracking params
        updateExistingLinks(pageName);

        if (game) {
            fetchPricing(game.dbname, function(pricingData) {
                var banner = createGameBanner(gameKey, pageName, pricingData);
                insertBanner(banner);
            });
        } else {
            fetchPricing('', function(pricingData) {
                var banner = createGenericBanner(pageName, pricingData);
                insertBanner(banner);
            });
        }
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }
})();

/**
 * SurvivalServers Wiki - Site Header / Dark Skin Injection v1.0 (2026-07)
 * Pairs with MediaWiki:Common.css design overhaul. Injects the main-site
 * header lockup (logo + WIKI tag, nav, search, breadcrumb) at the top of
 * every page and tags logged-in users so editor chrome stays visible.
 */
(function () {
    'use strict';

    if (document.getElementById('ssw-header-bar')) { return; }

    // real responsive viewport (legacy Vector pins width=1000)
    var vp = document.querySelector('meta[name="viewport"]');
    if (vp) { vp.setAttribute('content', 'width=device-width, initial-scale=1'); }

    // web font (Open Sans, same as panel)
    var pre = document.createElement('link');
    pre.rel = 'preconnect'; pre.href = 'https://fonts.googleapis.com';
    document.head.appendChild(pre);
    var font = document.createElement('link');
    font.rel = 'stylesheet';
    font.href = 'https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;600;700&display=swap';
    document.head.appendChild(font);

    var searchSvg = '<svg class="ssw-sicon" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><path fill="#666" d="M505 442.7L405.3 343c-4.5-4.5-10.6-7-17-7H372c27.6-35.3 44-79.7 44-128C416 93.1 322.9 0 208 0S0 93.1 0 208s93.1 208 208 208c48.3 0 92.7-16.4 128-44v16.3c0 6.4 2.5 12.5 7 17l99.7 99.7c9.4 9.4 24.6 9.4 33.9 0l28.3-28.3c9.4-9.4 9.4-24.6.1-34zM208 336c-70.7 0-128-57.2-128-128 0-70.7 57.2-128 128-128 70.7 0 128 57.2 128 128 0 70.7-57.2 128-128 128z"/></svg>';

    var isMain = mw.config.get('wgPageName') === 'Main_Page';
    var crumbHtml = '<a href="https://www.survivalservers.com/">Home</a><span class="sep">/</span>' +
        (isMain
            ? '<span class="ssw-cur">Wiki</span>'
            : '<a href="/wiki/index.php?title=Main_Page">Wiki</a><span class="sep">/</span><span class="ssw-cur"></span>');

    var wrap = document.createElement('div');
    wrap.id = 'ssw-header-bar';
    wrap.innerHTML =
        '<div class="ssw-topbar"><div class="ssw-topbar-in">' +
            '<span>Game server hosting since 2011</span>' +
            '<span>' +
                '<a href="https://www.survivalservers.com/sspanel/user/?support&new">Contact Us</a>' +
                '<a href="https://www.survivalservers.com/forum/">Forum</a>' +
                '<a href="https://x.com/survivalservers">X</a>' +
                '<a href="https://reddit.com/r/SurvivalServers">Reddit</a>' +
            '</span>' +
        '</div></div>' +
        '<div class="ssw-header"><div class="ssw-header-in">' +
            '<a class="ssw-logo" href="https://www.survivalservers.com/">' +
                '<img src="https://www.survivalservers.com/themes/epona/images/logo.png" alt="SurvivalServers">' +
                '<span class="ssw-wikitag">WIKI</span>' +
            '</a>' +
            '<form class="ssw-search" action="/wiki/index.php" method="get">' +
                searchSvg +
                '<input type="search" name="search" placeholder="Search the wiki...">' +
                '<input type="hidden" name="title" value="Special:Search">' +
            '</form>' +
            '<nav class="ssw-nav">' +
                '<a href="https://www.survivalservers.com/services/game_servers/">GAME SERVERS</a>' +
                '<a href="https://www.survivalservers.com/services/dedicated_servers/">DEDICATED SERVERS</a>' +
                '<a href="https://www.survivalservers.com/order/">ORDER</a>' +
                '<a href="https://www.survivalservers.com/about/">ABOUT</a>' +
                '<a class="ssw-cta" href="https://www.survivalservers.com/sspanel/">CONTROL PANEL</a>' +
            '</nav>' +
        '</div></div>' +
        '<div class="ssw-crumb">' + crumbHtml + '</div>';

    function insertHeader() {
        document.body.insertBefore(wrap, document.body.firstChild);
        var cur = wrap.querySelector('.ssw-cur');
        if (cur && !isMain) {
            cur.textContent = mw.config.get('wgTitle') || '';
            cur.style.color = '#ccc';
        }
        if (mw.config.get('wgUserName')) {
            document.body.className += ' ssw-user';
            // Vector puts #mw-head after the content in the DOM; move the
            // editor toolbar up under the injected header so it renders on top
            var head = document.getElementById('mw-head');
            if (head) { document.body.insertBefore(head, wrap.nextSibling); }
        }
    }

    if (document.body) {
        insertHeader();
    } else {
        document.addEventListener('DOMContentLoaded', insertHeader);
    }
})();
/**
 * SurvivalServers Wiki — v2 content enhancements (2026-07)
 * Pairs with the v2 Common.css pass. Appended to MediaWiki:Common.js AFTER
 * the header-injection block. Vanilla JS, no libraries, every feature
 * degrades gracefully if it can't run.
 *
 * Features:
 *   1. Article header meta (kicker + last-updated + read time + sections)
 *   2. NOTE/WARNING/TIP paragraph -> callout card conversion
 *   3. Terminal frames around .toccolours collapsibles (+ copy-keys button)
 *   4. Copy buttons on <pre> blocks
 *   5. TOC: body flag for the right rail, long-TOC columns, scroll-spy
 *   6. Image lightbox
 *   7. Sidebar active-page highlight (+ optional "Popular guides" portal)
 */
(function () {
    'use strict';

    // Optional curated portal in the sidebar. Leave empty to disable.
    // Entries: { title: 'ARK Advanced Configuration', href: '/wiki/index.php?title=ARK:_Survival_Evolved_Advanced_Configuration' }
    var POPULAR_GUIDES = [];

    function ready(fn) {
        if (document.readyState === 'loading') {
            document.addEventListener('DOMContentLoaded', fn);
        } else { fn(); }
    }

    function mwConf(key) {
        try { return window.mw && mw.config ? mw.config.get(key) : null; } catch (e) { return null; }
    }

    // ---------------------------------------------------- 1. article header
    function pageHeader() {
        var h1 = document.querySelector('#content h1.firstHeading');
        var parser = document.querySelector('.mw-parser-output');
        if (!h1 || h1.dataset.sswDone) { return; }
        h1.dataset.sswDone = '1';

        var isMain = (mwConf('wgPageName') || '') === 'Main_Page' ||
            /Main[_ ]Page/i.test(h1.textContent);

        var kicker = document.createElement('div');
        kicker.className = 'ssw-kicker';
        kicker.textContent = isMain ? 'SurvivalServers Wiki' : 'Server Guide';
        h1.parentNode.insertBefore(kicker, h1);

        var bits = [];
        var lastmod = document.getElementById('footer-info-lastmod');
        if (lastmod) {
            var m = lastmod.textContent.match(/last edited on (.+?), at/i);
            if (m) { bits.push('Updated <b>' + m[1] + '</b>'); }
        }
        if (parser) {
            var words = (parser.innerText || '').split(/\s+/).length;
            bits.push('<b>' + Math.max(1, Math.round(words / 220)) + ' min</b> read');
            var sections = parser.querySelectorAll(':scope > h2').length;
            if (sections > 1) { bits.push('<b>' + sections + '</b> sections'); }
        }
        if (bits.length) {
            var meta = document.createElement('div');
            meta.className = 'ssw-pagemeta';
            meta.innerHTML = bits.map(function (b) { return '<span>' + b + '</span>'; }).join('');
            h1.parentNode.insertBefore(meta, h1.nextSibling);
        }
    }

    // --------------------------------------------------------- 2. callouts
    var CALLOUT_MAP = {
        NOTE: 'ssw-note', NOTICE: 'ssw-note', INFO: 'ssw-note', IMPORTANT: 'ssw-warn',
        WARNING: 'ssw-warn', WARN: 'ssw-warn', CAUTION: 'ssw-danger', DANGER: 'ssw-danger',
        TIP: 'ssw-tip', HINT: 'ssw-tip'
    };
    function callouts() {
        var ps = document.querySelectorAll('.mw-parser-output p > b:first-child');
        for (var i = 0; i < ps.length; i++) {
            var b = ps[i], p = b.parentNode;
            if (p.classList.contains('ssw-callout')) { continue; }
            // <b> must be the first thing in the paragraph
            if (b.previousSibling && (b.previousSibling.textContent || '').trim() !== '') { continue; }
            var word = (b.textContent || '').replace(/[:\s]/g, '').toUpperCase();
            var cls = CALLOUT_MAP[word];
            if (!cls) { continue; }
            p.classList.add('ssw-callout', cls);
            b.textContent = word;
            // strip a leading ": " from the text node after the badge
            var next = b.nextSibling;
            if (next && next.nodeType === 3) {
                next.nodeValue = next.nodeValue.replace(/^[:\s]+/, ' ');
            }
        }
    }

    // ---------------------------------------------- 3. terminal collapsibles
    function copyToClipboard(text, btn) {
        function flash() {
            var old = btn.textContent;
            btn.textContent = 'COPIED';
            btn.classList.add('ssw-copied');
            setTimeout(function () { btn.textContent = old; btn.classList.remove('ssw-copied'); }, 1400);
        }
        if (navigator.clipboard && navigator.clipboard.writeText) {
            navigator.clipboard.writeText(text).then(flash, flash);
        } else {
            var ta = document.createElement('textarea');
            ta.value = text; ta.style.position = 'fixed'; ta.style.opacity = '0';
            document.body.appendChild(ta); ta.select();
            try { document.execCommand('copy'); } catch (e) { /* no-op */ }
            document.body.removeChild(ta);
            flash();
        }
    }

    function configKeyLines(box) {
        // top-level dd entries are "Key=Value" lines; nested dls are descriptions
        var lines = [];
        var dds = box.querySelectorAll('.mw-collapsible-content > dl > dd, :scope > dl > dd');
        for (var i = 0; i < dds.length; i++) {
            var clone = dds[i].cloneNode(true);
            var nested = clone.querySelectorAll('dl');
            for (var j = 0; j < nested.length; j++) { nested[j].parentNode.removeChild(nested[j]); }
            var t = (clone.textContent || '').trim();
            if (t) { lines.push(t); }
        }
        return lines.join('\n');
    }

    function terminals() {
        var boxes = document.querySelectorAll('.mw-parser-output .toccolours.mw-collapsible');
        for (var i = 0; i < boxes.length; i++) {
            (function (box) {
                if (box.parentNode.classList && box.parentNode.classList.contains('ssw-term')) { return; }

                var wrap = document.createElement('div');
                wrap.className = 'ssw-term';
                box.parentNode.insertBefore(wrap, box);

                var head = document.createElement('div');
                head.className = 'ssw-term-head';

                var hasImg = !!box.querySelector('img');
                var label = hasImg ? 'PANEL WALKTHROUGH' : 'CONFIG REFERENCE';

                head.innerHTML =
                    '<span class="ssw-dots"><i></i><i></i><i></i></span>' +
                    '<span class="ssw-term-label">' + label + '</span>';

                if (!hasImg && box.querySelector('dl > dd')) {
                    var copyBtn = document.createElement('button');
                    copyBtn.type = 'button';
                    copyBtn.className = 'ssw-copy';
                    copyBtn.textContent = 'COPY KEYS';
                    copyBtn.addEventListener('click', function (e) {
                        e.stopPropagation();
                        copyToClipboard(configKeyLines(box), copyBtn);
                    });
                    head.appendChild(copyBtn);
                }

                var chev = document.createElement('span');
                chev.className = 'ssw-term-chev';
                head.appendChild(chev);

                wrap.appendChild(head);
                wrap.appendChild(box);

                // whole header toggles the MW collapsible
                head.addEventListener('click', function () {
                    var toggle = box.querySelector('.mw-collapsible-toggle');
                    if (toggle) { toggle.click(); }
                });
            })(boxes[i]);
        }
    }

    // wait for jquery.makeCollapsible to have initialized (toggle spans exist);
    // fall back after ~5s so uninitialized boxes still get framed.
    function terminalsWhenReady() {
        var tries = 0;
        (function poll() {
            var anyBox = document.querySelector('.mw-parser-output .toccolours.mw-collapsible');
            if (!anyBox) { return; }
            if (anyBox.classList.contains('mw-made-collapsible') || tries >= 25) {
                terminals();
                return;
            }
            tries++;
            setTimeout(poll, 200);
        })();
    }

    // ------------------------------------------------------ 4. pre copy chip
    function preCopy() {
        var pres = document.querySelectorAll('.mw-parser-output pre');
        for (var i = 0; i < pres.length; i++) {
            (function (pre) {
                if (pre.querySelector('.ssw-copy')) { return; }
                var btn = document.createElement('button');
                btn.type = 'button';
                btn.className = 'ssw-copy';
                btn.textContent = 'COPY';
                btn.addEventListener('click', function () {
                    var clone = pre.cloneNode(true);
                    var b = clone.querySelector('.ssw-copy');
                    if (b) { b.parentNode.removeChild(b); }
                    copyToClipboard((clone.textContent || '').trim(), btn);
                });
                pre.appendChild(btn);
            })(pres[i]);
        }
    }

    // ----------------------------------------------- 5. TOC rail + scrollspy
    function toc() {
        var t = document.getElementById('toc');
        if (!t) { return; }
        document.body.classList.add('ssw-has-toc');
        var links = t.querySelectorAll('a[href^="#"]');
        if (links.length > 14) { t.classList.add('ssw-toc-long'); }

        // scroll-spy
        var targets = [];
        for (var i = 0; i < links.length; i++) {
            var id = decodeURIComponent(links[i].getAttribute('href').slice(1));
            var el = document.getElementById(id);
            if (el) { targets.push({ el: el, li: links[i].parentNode }); }
        }
        if (!targets.length) { return; }

        var current = null, ticking = false;
        function update() {
            ticking = false;
            var line = 110; // just under the sticky header
            var active = null;
            for (var i = 0; i < targets.length; i++) {
                if (targets[i].el.getBoundingClientRect().top <= line) { active = targets[i].li; }
                else { break; }
            }
            if (active === current) { return; }
            if (current) { current.classList.remove('ssw-current'); }
            current = active;
            if (current) {
                current.classList.add('ssw-current');
                // keep the highlighted row visible inside a scrolling rail
                if (t.scrollHeight > t.clientHeight + 4) {
                    var a = current.querySelector('a');
                    if (a) {
                        var rTop = a.offsetTop - t.scrollTop;
                        if (rTop < 40) { t.scrollTop = Math.max(0, a.offsetTop - 60); }
                        else if (rTop > t.clientHeight - 60) { t.scrollTop = a.offsetTop - t.clientHeight + 80; }
                    }
                }
            }
        }
        window.addEventListener('scroll', function () {
            if (!ticking) { ticking = true; requestAnimationFrame(update); }
        }, { passive: true });
        update();
    }

    // --------------------------------------------------------- 6. lightbox
    function lightbox() {
        document.addEventListener('click', function (e) {
            var a = e.target.closest && e.target.closest('.mw-parser-output a.image');
            if (!a) { return; }
            var img = a.querySelector('img');
            if (!img) { return; }
            e.preventDefault();
            var overlay = document.createElement('div');
            overlay.className = 'ssw-lightbox';
            var big = document.createElement('img');
            big.src = img.currentSrc || img.src;
            big.alt = img.alt || '';
            overlay.appendChild(big);
            if (img.alt) {
                var cap = document.createElement('figcaption');
                cap.textContent = img.alt.replace(/\.(png|jpe?g|gif|webp)$/i, '');
                overlay.appendChild(cap);
            }
            function close() {
                if (overlay.parentNode) { overlay.parentNode.removeChild(overlay); }
                document.removeEventListener('keydown', onKey);
            }
            function onKey(ev) { if (ev.key === 'Escape') { close(); } }
            overlay.addEventListener('click', close);
            document.addEventListener('keydown', onKey);
            document.body.appendChild(overlay);
        });
    }

    // ------------------------------------- 7. sidebar active + popular guides
    function sidebar() {
        var panel = document.getElementById('mw-panel');
        if (!panel) { return; }

        var page = mwConf('wgPageName');
        if (page) {
            var anchors = panel.querySelectorAll('.portal li a');
            for (var i = 0; i < anchors.length; i++) {
                var href = anchors[i].getAttribute('href') || '';
                var m = href.match(/[?&]title=([^&#]+)/) || href.match(/\/wiki\/(?:index\.php\/)?([^?&#]+)$/);
                if (m && decodeURIComponent(m[1]).replace(/\+/g, '_') === page) {
                    anchors[i].classList.add('ssw-side-active');
                }
            }
        }

        if (POPULAR_GUIDES.length) {
            var portal = document.createElement('div');
            portal.className = 'portal';
            portal.setAttribute('role', 'navigation');
            var items = '';
            for (var j = 0; j < POPULAR_GUIDES.length; j++) {
                items += '<li><a href="' + POPULAR_GUIDES[j].href + '">' + POPULAR_GUIDES[j].title + '</a></li>';
            }
            portal.innerHTML = '<h3>Popular guides</h3><div class="body"><ul>' + items + '</ul></div>';
            var first = panel.querySelector('.portal');
            if (first && first.nextSibling) { panel.insertBefore(portal, first.nextSibling); }
            else { panel.appendChild(portal); }
        }
    }

    ready(function () {
        try { pageHeader(); } catch (e) { /* no-op */ }
        try { callouts(); } catch (e) { /* no-op */ }
        try { terminalsWhenReady(); } catch (e) { /* no-op */ }
        try { preCopy(); } catch (e) { /* no-op */ }
        try { toc(); } catch (e) { /* no-op */ }
        try { lightbox(); } catch (e) { /* no-op */ }
        try { sidebar(); } catch (e) { /* no-op */ }
    });
})();