MediaWiki:Common.js

From Survival Servers
Revision as of 15:11, 8 December 2025 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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
 * Shows game-specific banners OR generic banner on all wiki pages
 * Includes affiliate tracking: trckaff=3881, trckit=WIKI<PageName>
 * 
 * Usage:
 * - Auto-detects game from page title
 * - Manual override: Add <!-- SSGAME:valheim --> anywhere in page
 * - Manual override: Add <div data-ss-game="valheim"></div> to page
 * - Generic banner shown on pages without game detection
 */
(function() {
    'use strict';

    // Tracking configuration
    var TRACK_AFF_ID = '3881';
    
    // Game configuration - maps keywords to game info
    var gameConfig = {
        'valheim': { name: 'Valheim', slug: 'valheim', color: '#1a472a' },
        'ark': { name: 'ARK: Survival Evolved', slug: 'ark', color: '#2d5a27' },
        'arksurvivalascended': { name: 'ARK: Survival Ascended', slug: 'arksurvivalascended', color: '#ff6b00' },
        'asa': { name: 'ARK: Survival Ascended', slug: 'arksurvivalascended', color: '#ff6b00' },
        'rust': { name: 'Rust', slug: 'rust', color: '#cd412b' },
        'minecraft': { name: 'Minecraft', slug: 'minecraft', color: '#62a851' },
        'palworld': { name: 'Palworld', slug: 'palworld', color: '#4a90d9' },
        'dayz': { name: 'DayZ', slug: 'dayz', color: '#1a1a1a' },
        'conan': { name: 'Conan Exiles', slug: 'conanexiles', color: '#8b4513' },
        '7daystodie': { name: '7 Days to Die', slug: '7daystodie', color: '#5c3d2e' },
        '7days': { name: '7 Days to Die', slug: '7daystodie', color: '#5c3d2e' },
        'theforest': { name: 'The Forest', slug: 'theforest', color: '#2d4a2d' },
        'forest': { name: 'The Forest', slug: 'theforest', color: '#2d4a2d' },
        'sonsoftheforest': { name: 'Sons of the Forest', slug: 'sonsoftheforest', color: '#1e3d1e' },
        'sons of the forest': { name: 'Sons of the Forest', slug: 'sonsoftheforest', color: '#1e3d1e' },
        'terraria': { name: 'Terraria', slug: 'terraria', color: '#4a8c4a' },
        'projectzomboid': { name: 'Project Zomboid', slug: 'projectzomboid', color: '#3d5c3d' },
        'zomboid': { name: 'Project Zomboid', slug: 'projectzomboid', color: '#3d5c3d' },
        'enshrouded': { name: 'Enshrouded', slug: 'enshrouded', color: '#6b4423' },
        'satisfactory': { name: 'Satisfactory', slug: 'satisfactory', color: '#d97c2b' },
        'v rising': { name: 'V Rising', slug: 'vrising', color: '#8b0000' },
        'vrising': { name: 'V Rising', slug: 'vrising', color: '#8b0000' },
        'aska': { name: 'ASKA', slug: 'aska', color: '#4a6b8a' },
        'unturned': { name: 'Unturned', slug: 'unturned', color: '#6b8e23' },
        'factorio': { name: 'Factorio', slug: 'factorio', color: '#ff7b00' },
        'csgo': { name: 'CS2', slug: 'csgo', color: '#de9b35' },
        'cs2': { name: 'CS2', slug: 'csgo', color: '#de9b35' },
        'counterstrike': { name: 'CS2', slug: 'csgo', color: '#de9b35' },
        'counter-strike': { name: 'CS2', slug: 'csgo', color: '#de9b35' },
        'theisle': { name: 'The Isle', slug: 'theisle', color: '#2e4a2e' },
        'isle': { name: 'The Isle', slug: 'theisle', color: '#2e4a2e' },
        'squad': { name: 'Squad', slug: 'squad', color: '#5a5a3d' },
        'arma': { name: 'Arma 3', slug: 'arma3', color: '#4a4a2d' },
        'starbound': { name: 'Starbound', slug: 'starbound', color: '#1a3d5c' },
        'empyrion': { name: 'Empyrion', slug: 'empyrion', color: '#1a4a6b' },
        'pixark': { name: 'PixARK', slug: 'pixark', color: '#4a7a4a' },
        'dontstarve': { name: "Don't Starve Together", slug: 'dontstarve', color: '#3d3d3d' },
        "don't starve": { name: "Don't Starve Together", slug: 'dontstarve', color: '#3d3d3d' },
        'starve': { name: "Don't Starve Together", slug: 'dontstarve', color: '#3d3d3d' },
        'scum': { name: 'SCUM', slug: 'scum', color: '#5c4a2d' },
        'barotrauma': { name: 'Barotrauma', slug: 'barotrauma', color: '#1a3d5c' },
        'corekeeper': { name: 'Core Keeper', slug: 'corekeeper', color: '#6b4a23' },
        'core keeper': { name: 'Core Keeper', slug: 'corekeeper', color: '#6b4a23' },
        'stationeers': { name: 'Stationeers', slug: 'stationeers', color: '#2d4a5c' },
        'icarus': { name: 'Icarus', slug: 'icarus', color: '#4a6b8a' },
        'avorion': { name: 'Avorion', slug: 'avorion', color: '#2d5a6b' },
        'spaceengineers': { name: 'Space Engineers', slug: 'spaceengineers', color: '#1a2a4a' },
        'space engineers': { name: 'Space Engineers', slug: 'spaceengineers', color: '#1a2a4a' },
        'mordhau': { name: 'Mordhau', slug: 'mordhau', color: '#5c3d2d' },
        'hurtworld': { name: 'Hurtworld', slug: 'hurtworld', color: '#8b5a2b' },
        'miscreated': { name: 'Miscreated', slug: 'miscreated', color: '#3d4a3d' },
        'fivem': { name: 'FiveM', slug: 'fivem', color: '#f26419' },
        'redm': { name: 'RedM', slug: 'redm', color: '#8b2500' },
        'assettocorsa': { name: 'Assetto Corsa', slug: 'assettocorsa', color: '#cc0000' },
        'assetto corsa': { name: 'Assetto Corsa', slug: 'assettocorsa', color: '#cc0000' },
        'assetto': { name: 'Assetto Corsa', slug: 'assettocorsa', color: '#cc0000' },
        'renown': { name: 'Renown', slug: 'renown', color: '#4a3d6b' },
        'brickadia': { name: 'Brickadia', slug: 'brickadia', color: '#e74c3c' },
        'holdfast': { name: 'Holdfast: Nations At War', slug: 'holdfast', color: '#8b4513' },
        'left4dead2': { name: 'Left 4 Dead 2', slug: 'left4dead2', color: '#8b0000' },
        'left 4 dead': { name: 'Left 4 Dead 2', slug: 'left4dead2', color: '#8b0000' },
        'l4d2': { name: 'Left 4 Dead 2', slug: 'left4dead2', color: '#8b0000' },
        'deadmatter': { name: 'Dead Matter', slug: 'deadmatter', color: '#2d3d2d' },
        'dead matter': { name: 'Dead Matter', slug: 'deadmatter', color: '#2d3d2d' },
        'soulmask': { name: 'Soulmask', slug: 'soulmask', color: '#4a5a3d' },
        'nightingale': { name: 'Nightingale', slug: 'nightingale', color: '#5c4a6b' }
    };

    function getPageName() {
        // Get page name from URL or title, sanitized for tracking
        var urlParams = new URLSearchParams(window.location.search);
        var title = urlParams.get('title');
        
        if (!title) {
            // Try to get from URL path
            var path = window.location.pathname;
            var match = path.match(/\/wiki\/(.+)$/);
            if (match) {
                title = decodeURIComponent(match[1]);
            }
        }
        
        if (!title) {
            // Fall back to page title element
            var heading = document.getElementById('firstHeading');
            if (heading) {
                title = heading.textContent;
            }
        }
        
        // Sanitize: replace spaces/special chars with underscores, limit length
        if (title) {
            title = title.replace(/[^a-zA-Z0-9]/g, '_').replace(/_+/g, '_').substring(0, 50);
        }
        
        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');
        
        // Check for manual game specification via data attribute
        var manualGame = document.querySelector('[data-ss-game]');
        if (manualGame) {
            return manualGame.getAttribute('data-ss-game').toLowerCase();
        }
        
        // Check for special comment/marker in page content
        var content = bodyContent ? bodyContent.innerHTML : '';
        var markerMatch = content.match(/<!--\s*SSGAME:\s*(\w+)\s*-->/i);
        if (markerMatch) {
            return markerMatch[1].toLowerCase();
        }
        
        // Auto-detect from page title - check longer keywords first
        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.style.cssText = 'background: linear-gradient(135deg, ' + game.color + ' 0%, ' + adjustColor(game.color, -30) + ' 100%); border-radius: 12px; padding: 20px 30px; margin: 0 0 25px 0; box-shadow: 0 4px 20px rgba(0,0,0,0.3); display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 15px;';
        
        banner.innerHTML = 
            '<div style="display: flex; align-items: center; gap: 20px; flex: 1; min-width: 280px;">' +
                '<div style="width: 60px; height: 60px; background: rgba(255,255,255,0.15); border-radius: 12px; display: flex; align-items: center; justify-content: center;">' +
                    '<svg width="36" height="36" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5"/></svg>' +
                '</div>' +
                '<div>' +
                    '<div style="color: rgba(255,255,255,0.85); font-size: 13px; text-transform: uppercase; letter-spacing: 1.5px; margin-bottom: 4px; font-weight: 500;">Premium Game Server Hosting</div>' +
                    '<div style="color: white; font-size: 22px; font-weight: 700;">' + game.name + ' Servers</div>' +
                    '<div style="color: rgba(255,255,255,0.9); font-size: 14px; margin-top: 4px;">⚡ Instant Setup • 🌍 Global Locations • 🛡️ DDoS Protection • 💬 24/7 Support</div>' +
                '</div>' +
            '</div>' +
            '<a href="' + trackingUrl + '" target="_blank" style="background: white; color: ' + game.color + '; padding: 14px 32px; border-radius: 8px; text-decoration: none; font-weight: 700; font-size: 16px; display: inline-flex; align-items: center; gap: 8px; transition: all 0.3s ease; box-shadow: 0 2px 10px rgba(0,0,0,0.2);" onmouseover="this.style.transform=\'translateY(-2px)\';this.style.boxShadow=\'0 4px 15px rgba(0,0,0,0.3)\';" onmouseout="this.style.transform=\'translateY(0)\';this.style.boxShadow=\'0 2px 10px rgba(0,0,0,0.2)\';">' +
                'Order Now ' +
                '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><path d="M5 12h14M12 5l7 7-7 7"/></svg>' +
            '</a>';

        return banner;
    }

    function createGenericBanner(pageName) {
        var trackingUrl = buildTrackingUrl('https://www.survivalservers.com/', pageName);
        
        var banner = document.createElement('div');
        banner.id = 'ss-game-banner';
        banner.style.cssText = 'background: linear-gradient(135deg, #1e3a5f 0%, #0d1b2a 100%); border-radius: 12px; padding: 20px 30px; margin: 0 0 25px 0; box-shadow: 0 4px 20px rgba(0,0,0,0.3); display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 15px;';
        
        banner.innerHTML = 
            '<div style="display: flex; align-items: center; gap: 20px; flex: 1; min-width: 280px;">' +
                '<div style="width: 60px; height: 60px; background: rgba(255,255,255,0.15); border-radius: 12px; display: flex; align-items: center; justify-content: center;">' +
                    '<svg width="36" height="36" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5"/></svg>' +
                '</div>' +
                '<div>' +
                    '<div style="color: rgba(255,255,255,0.85); font-size: 13px; text-transform: uppercase; letter-spacing: 1.5px; margin-bottom: 4px; font-weight: 500;">Trusted Since 2012</div>' +
                    '<div style="color: white; font-size: 22px; font-weight: 700;">SurvivalServers.com</div>' +
                    '<div style="color: rgba(255,255,255,0.9); font-size: 14px; margin-top: 4px;">🎮 100+ Games • ⚡ Instant Setup • 🌍 9 Global Locations • 💬 24/7 Expert Support</div>' +
                '</div>' +
            '</div>' +
            '<a href="' + trackingUrl + '" target="_blank" style="background: linear-gradient(135deg, #00b4d8 0%, #0077b6 100%); color: white; padding: 14px 32px; border-radius: 8px; text-decoration: none; font-weight: 700; font-size: 16px; display: inline-flex; align-items: center; gap: 8px; transition: all 0.3s ease; box-shadow: 0 2px 10px rgba(0,0,0,0.2);" onmouseover="this.style.transform=\'translateY(-2px)\';this.style.boxShadow=\'0 4px 15px rgba(0,0,0,0.3)\';" onmouseout="this.style.transform=\'translateY(0)\';this.style.boxShadow=\'0 2px 10px rgba(0,0,0,0.2)\';">' +
                'Browse Games ' +
                '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><path d="M5 12h14M12 5l7 7-7 7"/></svg>' +
            '</a>';

        return banner;
    }

    function adjustColor(hex, amount) {
        hex = hex.replace('#', '');
        var r = Math.max(0, Math.min(255, parseInt(hex.substr(0,2), 16) + amount));
        var g = Math.max(0, Math.min(255, parseInt(hex.substr(2,2), 16) + amount));
        var b = Math.max(0, Math.min(255, parseInt(hex.substr(4,2), 16) + amount));
        return '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
    }

    function init() {
        // Don't show on Main Page
        var pageTitle = document.title;
        if (pageTitle.indexOf('Main Page') !== -1) {
            return;
        }
        
        // Don't show on Special pages
        if (window.location.href.indexOf('Special:') !== -1) {
            return;
        }

        var pageName = getPageName();
        var gameKey = detectGame();
        var banner;
        
        if (gameKey && gameConfig[gameKey]) {
            banner = createGameBanner(gameKey, pageName);
        } else {
            banner = createGenericBanner(pageName);
        }
        
        if (!banner) return;

        // Insert banner at the top of content area
        var contentDiv = document.getElementById('bodyContent');
        if (contentDiv) {
            contentDiv.insertBefore(banner, contentDiv.firstChild);
        }
    }

    // Run when DOM is ready
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }
})();