MediaWiki:Common.js

From Survival Servers
Revision as of 15:18, 8 December 2025 by Maintenance script (talk | contribs)
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)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/**
 * SurvivalServers Wiki - Game Server Banner System
 * Dark theme with gold accents matching main site design
 * Includes affiliate tracking: trckaff=3881, trckit=WIKI<PageName>
 */
(function() {
    'use strict';

    var TRACK_AFF_ID = '3881';
    var MAX_TRCKIT_LENGTH = 41;
    
    var gameConfig = {
        'valheim': { name: 'Valheim', slug: 'valheim' },
        'ark': { name: 'ARK: Survival Evolved', slug: 'ark' },
        'arksurvivalascended': { name: 'ARK: Survival Ascended', slug: 'arksurvivalascended' },
        'asa': { name: 'ARK: Survival Ascended', slug: 'arksurvivalascended' },
        'rust': { name: 'Rust', slug: 'rust' },
        'minecraft': { name: 'Minecraft', slug: 'minecraft' },
        'palworld': { name: 'Palworld', slug: 'palworld' },
        'dayz': { name: 'DayZ', slug: 'dayz' },
        'conan': { name: 'Conan Exiles', slug: 'conanexiles' },
        '7daystodie': { name: '7 Days to Die', slug: '7daystodie' },
        '7days': { name: '7 Days to Die', slug: '7daystodie' },
        'theforest': { name: 'The Forest', slug: 'theforest' },
        'forest': { name: 'The Forest', slug: 'theforest' },
        'sonsoftheforest': { name: 'Sons of the Forest', slug: 'sonsoftheforest' },
        'sons of the forest': { name: 'Sons of the Forest', slug: 'sonsoftheforest' },
        'terraria': { name: 'Terraria', slug: 'terraria' },
        'projectzomboid': { name: 'Project Zomboid', slug: 'projectzomboid' },
        'zomboid': { name: 'Project Zomboid', slug: 'projectzomboid' },
        'enshrouded': { name: 'Enshrouded', slug: 'enshrouded' },
        'satisfactory': { name: 'Satisfactory', slug: 'satisfactory' },
        'v rising': { name: 'V Rising', slug: 'vrising' },
        'vrising': { name: 'V Rising', slug: 'vrising' },
        'aska': { name: 'ASKA', slug: 'aska' },
        'unturned': { name: 'Unturned', slug: 'unturned' },
        'factorio': { name: 'Factorio', slug: 'factorio' },
        'csgo': { name: 'CS2', slug: 'csgo' },
        'cs2': { name: 'CS2', slug: 'csgo' },
        'counterstrike': { name: 'CS2', slug: 'csgo' },
        'theisle': { name: 'The Isle', slug: 'theisle' },
        'isle': { name: 'The Isle', slug: 'theisle' },
        'squad': { name: 'Squad', slug: 'squad' },
        'arma': { name: 'Arma 3', slug: 'arma3' },
        'starbound': { name: 'Starbound', slug: 'starbound' },
        'empyrion': { name: 'Empyrion', slug: 'empyrion' },
        'pixark': { name: 'PixARK', slug: 'pixark' },
        'dontstarve': { name: "Don't Starve Together", slug: 'dontstarve' },
        "don't starve": { name: "Don't Starve Together", slug: 'dontstarve' },
        'scum': { name: 'SCUM', slug: 'scum' },
        'barotrauma': { name: 'Barotrauma', slug: 'barotrauma' },
        'corekeeper': { name: 'Core Keeper', slug: 'corekeeper' },
        'core keeper': { name: 'Core Keeper', slug: 'corekeeper' },
        'stationeers': { name: 'Stationeers', slug: 'stationeers' },
        'icarus': { name: 'Icarus', slug: 'icarus' },
        'avorion': { name: 'Avorion', slug: 'avorion' },
        'spaceengineers': { name: 'Space Engineers', slug: 'spaceengineers' },
        'space engineers': { name: 'Space Engineers', slug: 'spaceengineers' },
        'mordhau': { name: 'Mordhau', slug: 'mordhau' },
        'hurtworld': { name: 'Hurtworld', slug: 'hurtworld' },
        'miscreated': { name: 'Miscreated', slug: 'miscreated' },
        'fivem': { name: 'FiveM', slug: 'fivem' },
        'redm': { name: 'RedM', slug: 'redm' },
        'assettocorsa': { name: 'Assetto Corsa', slug: 'assettocorsa' },
        'assetto': { name: 'Assetto Corsa', slug: 'assettocorsa' },
        'renown': { name: 'Renown', slug: 'renown' },
        'brickadia': { name: 'Brickadia', slug: 'brickadia' },
        'holdfast': { name: 'Holdfast: Nations At War', slug: 'holdfast' },
        'left4dead': { name: 'Left 4 Dead 2', slug: 'left4dead2' },
        'l4d2': { name: 'Left 4 Dead 2', slug: 'left4dead2' },
        'deadmatter': { name: 'Dead Matter', slug: 'deadmatter' },
        'soulmask': { name: 'Soulmask', slug: 'soulmask' },
        'nightingale': { name: 'Nightingale', slug: 'nightingale' },
        'abiotic': { name: 'Abiotic Factor', slug: 'abiotic_factor' },
        'abiotic factor': { name: 'Abiotic Factor', slug: 'abiotic_factor' }
    };

    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 createGameBanner(gameKey, pageName) {
        var game = gameConfig[gameKey];
        if (!game) return null;
        var trackingUrl = buildTrackingUrl('https://www.survivalservers.com/services/game_servers/' + game.slug + '/', pageName);

        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: 18px 25px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 15px;">' +
                '<div style="display: flex; align-items: center; gap: 20px; flex: 1; min-width: 280px;">' +
                    '<div style="color: rgb(219, 155, 21); font-weight: 700; font-size: 14px; white-space: nowrap;">SURVIVAL SERVERS</div>' +
                    '<div style="color: #fff; font-size: 15px;">' +
                        '<span style="color: rgb(219, 155, 21); font-weight: 600;">' + game.name + ' Server Hosting</span>' +
                        '<span style="color: rgba(255,255,255,0.7); margin: 0 12px;">|</span>' +
                        '<span style="color: rgba(255,255,255,0.9);">Instant Setup</span>' +
                        '<span style="color: rgba(255,255,255,0.5); margin: 0 8px;">&#8226;</span>' +
                        '<span style="color: rgba(255,255,255,0.9);">9 Locations</span>' +
                        '<span style="color: rgba(255,255,255,0.5); margin: 0 8px;">&#8226;</span>' +
                        '<span style="color: rgba(255,255,255,0.9);">24/7 Support</span>' +
                    '</div>' +
                '</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;" 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)\';">' +
                    'Order Now <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3"><path d="M5 12h14M12 5l7 7-7 7"/></svg>' +
                '</a>' +
            '</div>' +
        '</div>';
        return banner;
    }

    function createGenericBanner(pageName) {
        var trackingUrl = buildTrackingUrl('https://www.survivalservers.com/', pageName);
        
        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: 18px 25px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 15px;">' +
                '<div style="display: flex; align-items: center; gap: 20px; flex: 1; min-width: 280px;">' +
                    '<div style="color: rgb(219, 155, 21); font-weight: 700; font-size: 14px; white-space: nowrap;">SURVIVAL SERVERS</div>' +
                    '<div style="color: #fff; font-size: 15px;">' +
                        '<span style="color: rgb(219, 155, 21); font-weight: 600;">Game Server Hosting</span>' +
                        '<span style="color: rgba(255,255,255,0.7); margin: 0 12px;">|</span>' +
                        '<span style="color: rgba(255,255,255,0.9);">100+ Games</span>' +
                        '<span style="color: rgba(255,255,255,0.5); margin: 0 8px;">&#8226;</span>' +
                        '<span style="color: rgba(255,255,255,0.9);">Instant Setup</span>' +
                        '<span style="color: rgba(255,255,255,0.5); margin: 0 8px;">&#8226;</span>' +
                        '<span style="color: rgba(255,255,255,0.9);">24/7 Support</span>' +
                    '</div>' +
                '</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;" 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)\';">' +
                    'Browse Games <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3"><path d="M5 12h14M12 5l7 7-7 7"/></svg>' +
                '</a>' +
            '</div>' +
        '</div>';
        return banner;
    }

    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 banner = (gameKey && gameConfig[gameKey]) ? createGameBanner(gameKey, pageName) : createGenericBanner(pageName);
        
        if (!banner) return;
        var contentDiv = document.getElementById('bodyContent');
        if (contentDiv) contentDiv.insertBefore(banner, contentDiv.firstChild);
    }

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