DF Quick link

Quick navigation buttons for Dead Frontier

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         DF Quick link
// @namespace    http://tampermonkey.net/
// @version      1.5.3
// @description  Quick navigation buttons for Dead Frontier
// @author       SHUN
// @license      SHUN
// @match        *://fairview.deadfrontier.com/onlinezombiemmo/*
// @match        *://*.deadfrontier.com/onlinezombiemmo/*
// @icon         https://i.imgur.com/wDmstST.png
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    console.log('Quick Navigation Panel script started');

    // Wait for page to load
    let checkCount = 0;
    const maxChecks = 20;

    function checkPageLoaded() {
        checkCount++;

        // Check if page has enough content
        if (document.body && document.body.innerHTML.length > 1000) {
            console.log('Page loaded, creating button panel');
            createButtonPanel();
            return;
        }

        // Continue waiting if not loaded
        if (checkCount < maxChecks) {
            console.log('Waiting for page to load... (' + checkCount + '/' + maxChecks + ')');
            setTimeout(checkPageLoaded, 500);
        } else {
            // Force creation after max wait time
            console.log('Max wait time reached, creating panel anyway');
            createButtonPanel();
        }
    }

    function createButtonPanel() {
        // Check if already exists
        if (document.getElementById('quick-navigation-panel')) {
            console.log('Navigation panel already exists');
            return;
        }

        // Create container
        const container = createButtonContainer();
        document.body.appendChild(container);

        // Set position
        setCustomPosition(container);

        // Listen for window resize
        window.addEventListener('resize', function() {
            setCustomPosition(container);
        });

        // Add animation
        addRainbowAnimation();

        console.log('Navigation panel created successfully');
    }

    // Create button container
    function createButtonContainer() {
        const container = document.createElement('div');
        container.id = 'quick-navigation-panel';
        container.style.position = 'fixed';
        container.style.zIndex = '1000';
        container.style.backgroundImage = 'url("https://i.imgur.com/icHXrC4.jpeg")';
        container.style.backgroundSize = 'cover';
        container.style.padding = '8px';
        container.style.borderRadius = '50px';
        container.style.display = 'flex';
        container.style.flexDirection = 'column';
        container.style.gap = '5px';
        container.style.width = '60px';
        container.style.height = 'auto';

        // Create buttons
        const buttons = [
            { name: 'Fast Travel', link: 'https://fairview.deadfrontier.com/onlinezombiemmo/index.php?page=61' },
            { name: 'Crafting', link: 'https://fairview.deadfrontier.com/onlinezombiemmo/index.php?page=59' },
            { name: 'Gambling', link: 'https://fairview.deadfrontier.com/onlinezombiemmo/index.php?page=49' },
            { name: 'Convenience', link: 'https://fairview.deadfrontier.com/onlinezombiemmo/index.php?page=84' },
            { name: 'Profile', link: 'https://fairview.deadfrontier.com/onlinezombiemmo/index.php?action=profile' },
            { name: 'Market', link: 'https://fairview.deadfrontier.com/onlinezombiemmo/index.php?page=35' },
            { name: 'Bank', link: 'https://fairview.deadfrontier.com/onlinezombiemmo/index.php?page=15' },
            { name: 'Storage', link: 'https://fairview.deadfrontier.com/onlinezombiemmo/index.php?page=50' },
            { name: 'Park', link: 'https://fairview.deadfrontier.com/onlinezombiemmo/index.php?page=24' },
            { name: 'Inner City', link: 'https://fairview.deadfrontier.com/onlinezombiemmo/index.php?page=0' },
        ];

        buttons.forEach(function(buttonInfo) {
            createQuickNavigationButton(container, buttonInfo.name, buttonInfo.link);
        });

        // Add move button
        createMoveButton(container);

        return container;
    }

    // Create navigation button
    function createQuickNavigationButton(container, buttonTitle, url) {
        const button = document.createElement("button");
        button.textContent = buttonTitle;
        button.id = buttonTitle;
        button.style.height = "max-content";
        button.style.padding = "5px";
        button.style.margin = "2px";
        button.style.border = "1px solid #666";
        button.style.borderRadius = "4px";
        button.style.background = "#4a4a4a";
        button.style.color = "white";
        button.style.cursor = "pointer";
        button.style.fontSize = "12px";

        button.addEventListener("click", function() {
            window.location.href = url;
        });

        // Mouse hover effects
        button.addEventListener('mouseover', function() {
            button.style.animation = 'rainbow 3s infinite';
            button.style.background = '#666';
        });

        button.addEventListener('mouseout', function() {
            button.style.animation = '';
            button.style.background = '#4a4a4a';
        });

        container.appendChild(button);
    }

    // Create move button
    function createMoveButton(container) {
        const moveButton = document.createElement("button");
        moveButton.textContent = "Move Panel";
        moveButton.style.padding = '10px';
        moveButton.style.margin = '2px';
        moveButton.style.border = 'none';
        moveButton.style.borderRadius = '5px';
        moveButton.style.backgroundColor = '#28a745';
        moveButton.style.color = 'white';
        moveButton.style.cursor = 'pointer';
        moveButton.style.fontSize = '12px';

        moveButton.addEventListener('mousedown', function(e) {
            e.preventDefault();
            e.stopPropagation();

            const offsetX = e.clientX - container.getBoundingClientRect().left;
            const offsetY = e.clientY - container.getBoundingClientRect().top;

            function mouseMoveHandler(e) {
                container.style.left = (e.clientX - offsetX) + 'px';
                container.style.top = (e.clientY - offsetY) + 'px';
                container.style.right = 'auto';
            }

            function mouseUpHandler() {
                document.removeEventListener('mousemove', mouseMoveHandler);
                document.removeEventListener('mouseup', mouseUpHandler);
            }

            document.addEventListener('mousemove', mouseMoveHandler);
            document.addEventListener('mouseup', mouseUpHandler);
        });

        container.appendChild(moveButton);
    }

    // Set custom position
    function setCustomPosition(container) {
        // Check for saved position
        const savedLeft = localStorage.getItem('quickNav_left');
        const savedTop = localStorage.getItem('quickNav_top');

        if (savedLeft && savedTop) {
            container.style.left = savedLeft + 'px';
            container.style.top = savedTop + 'px';
            container.style.right = 'auto';
            return;
        }

        // Default position
        if (window.innerWidth <= 960) {
            // Mobile/tablet
            container.style.left = '10px';
            container.style.top = '600px';
            container.style.right = 'auto';
        } else {
            // Desktop
            container.style.left = '10px';
            container.style.top = '230px';
            container.style.right = 'auto';
        }
    }

    // Add rainbow animation
    function addRainbowAnimation() {
        // Check if already added
        if (document.getElementById('rainbow-style')) return;

        const style = document.createElement('style');
        style.id = 'rainbow-style';
        style.textContent = `
            @keyframes rainbow {
                0% { background-color: red; }
                14% { background-color: orange; }
                28% { background-color: yellow; }
                42% { background-color: green; }
                57% { background-color: blue; }
                71% { background-color: indigo; }
                85% { background-color: violet; }
                100% { background-color: red; }
            }
        `;
        document.head.appendChild(style);
    }

    // Save position to localStorage
    function savePosition(container) {
        localStorage.setItem('quickNav_left', container.style.left.replace('px', ''));
        localStorage.setItem('quickNav_top', container.style.top.replace('px', ''));
    }

    // Start checking page
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', checkPageLoaded);
    } else {
        setTimeout(checkPageLoaded, 1000);
    }

    // Listen for window close to save position
    window.addEventListener('beforeunload', function() {
        const container = document.getElementById('quick-navigation-panel');
        if (container) {
            savePosition(container);
        }
    });

})();