Silkroad Online Türkiye

Oyun sunucu durumunu ekranda gösterir ve sesli bildirim sağlar.

// ==UserScript==
// @name         Silkroad Online Türkiye
// @namespace    http://tampermonkey.net/
// @version      2.5
// @description  Oyun sunucu durumunu ekranda gösterir ve sesli bildirim sağlar.
// @author       inos
// @match        *://*/*
// @grant        GM_xmlhttpRequest
// @grant        GM_addStyle
// @grant        GM_setValue
// @grant        GM_getValue
// @connect      silkroad.gamegami.com
// ==/UserScript==

(function() {
    'use strict';

    const serverStatusUrl = 'https://silkroad.gamegami.com/stats.php';


    let statusBox = document.createElement('div');
    statusBox.id = 'serverStatusBox';
    statusBox.innerHTML = '<b>TRSRO SUNUCU DURUMU</b><br>Yükleniyor...<br>';


    let buttonContainer = document.createElement('div');
    buttonContainer.id = 'buttonContainer';
    statusBox.appendChild(buttonContainer);


    let refreshButton = document.createElement('div');
    refreshButton.id = 'refreshButton';
    refreshButton.classList.add('button-icon');
    refreshButton.innerHTML = '<img src="https://cdn-icons-png.flaticon.com/512/188/188925.png" alt="Yenile">';
    refreshButton.onclick = function() {
        fetchServerStatus();
    };
    let refreshTooltip = document.createElement('span');
    refreshTooltip.classList.add('tooltip-text');
    refreshTooltip.innerText = 'Yenile';
    refreshButton.appendChild(refreshTooltip);
    buttonContainer.appendChild(refreshButton);


    let creatorButton = document.createElement('div');
    creatorButton.id = 'creatorButton';
    creatorButton.classList.add('button-icon');
    creatorButton.innerHTML = '<img src="https://cdn-icons-png.flaticon.com/512/3135/3135715.png" alt="Yapımcı">';
    creatorButton.onclick = function() {
        window.open('https://silkroad.gamegami.com/character.php?shardid=18&char=inos', '_blank');
    };
    let creatorTooltip = document.createElement('span');
    creatorTooltip.classList.add('tooltip-text');
    creatorTooltip.innerText = 'Yapımcı';
    creatorButton.appendChild(creatorTooltip);
    buttonContainer.appendChild(creatorButton);


    let registerButton = document.createElement('div');
    registerButton.id = 'registerButton';
    registerButton.classList.add('button-icon');
    registerButton.innerHTML = '<img src="https://cdn-icons-png.flaticon.com/512/1146/1146869.png" alt="Kayıt Ol">'; // Kayıt ikonu
    registerButton.onclick = function() {
        window.open('https://silkroad.gamegami.com/register.php', '_blank');
    };
    let registerTooltip = document.createElement('span');
    registerTooltip.classList.add('tooltip-text');
    registerTooltip.innerText = 'Kayıt Ol';
    registerButton.appendChild(registerTooltip);
    buttonContainer.appendChild(registerButton);


    let downloadButton = document.createElement('div');
    downloadButton.id = 'downloadButton';
    downloadButton.classList.add('button-icon');
    downloadButton.innerHTML = '<img src="https://cdn-icons-png.flaticon.com/512/3001/3001111.png" alt="İndir">';
    downloadButton.onclick = function() {
        window.open('https://silkroad.gamegami.com/download.php', '_blank');
    };
    let downloadTooltip = document.createElement('span');
    downloadTooltip.classList.add('tooltip-text');
    downloadTooltip.innerText = 'İndir';
    downloadButton.appendChild(downloadTooltip);
    buttonContainer.appendChild(downloadButton);


    let colorChangeButton = document.createElement('div');
    colorChangeButton.id = 'colorChangeButton';
    colorChangeButton.classList.add('button-icon');
    colorChangeButton.innerHTML = '<img src="https://cdn-icons-png.flaticon.com/512/139/139899.png" alt="Renk Değiştir">'; // Güncel renk değiştirme ikonu
    colorChangeButton.onclick = function() {
        changeColor();
    };
    let colorChangeTooltip = document.createElement('span');
    colorChangeTooltip.classList.add('tooltip-text');
    colorChangeTooltip.innerText = 'Renk Değiştir';
    colorChangeButton.appendChild(colorChangeTooltip);
    buttonContainer.appendChild(colorChangeButton);

    document.body.appendChild(statusBox);

    GM_addStyle(`
        #serverStatusBox {
            position: fixed;
            bottom: 10px;
            right: 10px;
            background: rgba(0, 0, 0, 0.7);
            color: white;
            padding: 10px;
            border-radius: 8px;
            font-size: 14px;
            z-index: 9999;
            min-width: 200px;
            text-align: left;
        }
        .server-entry {
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid rgba(255, 255, 255, 0.3);
            padding: 5px 0;
        }
        .server-name {
            font-weight: bold;
            flex: 1;
        }
        .server-status {
            flex: 1;
            text-align: center;
        }
        .status-indicator {
            display: inline-block;
            width: 10px;
            height: 10px;
            border-radius: 50%;
            margin-left: 5px;
        }
        #buttonContainer {
            display: flex;
            margin-top: 5px;
        }
        .button-icon {
            position: relative;
            margin-right: 5px;
            cursor: pointer;
            width: 30px;
            height: 30px;
            display: flex;
            justify-content: center;
            align-items: center;
            border-radius: 5px;
            background-color: rgba(0, 0, 0, 0.7);
            padding: 3px;
        }
        .button-icon:hover {
            background-color: rgba(0, 0, 0, 0.9);
        }
        .button-icon img {
            width: 20px;
            height: 20px;
        }
        .tooltip-text {
            visibility: hidden;
            position: absolute;
            bottom: 40px;
            background-color: black;
            color: white;
            text-align: center;
            border-radius: 5px;
            padding: 5px;
            z-index: 10;
            width: 100px;
        }
        .button-icon:hover .tooltip-text {
            visibility: visible;
        }
    `);

    // Sunucu durumlarını getiren fonksiyon
    function fetchServerStatus() {
        GM_xmlhttpRequest({
            method: 'GET',
            url: serverStatusUrl,
            headers: { 'Cache-Control': 'no-cache' },
            onload: function(response) {
                let parser = new DOMParser();
                let doc = parser.parseFromString(response.responseText, 'text/html');
                let servers = doc.querySelectorAll('tbody tr');
                let statusText = '<b>TRSRO SUNUCU DURUMU</b><br>';

                if (servers.length === 0) {
                    statusBox.innerHTML = 'Sunucu bilgisi bulunamadı!';
                    return;
                }

                let validServers = 0;
                servers.forEach(row => {
                    let nameElement = row.querySelector('.td1');
                    let capacityElement = row.querySelector('.td2');
                    let statusElement = row.querySelector('.td4 div:last-child');

                    if (nameElement && capacityElement && statusElement) {
                        let name = nameElement.textContent.trim();
                        let capacity = capacityElement.textContent.trim().replace('%', '');
                        let status = statusElement.textContent.trim();
                        let capacityNumber = parseInt(capacity, 10);

                        let color = 'gray';
                        if (capacityNumber >= 75) color = 'red';
                        else if (capacityNumber >= 50) color = 'orange';
                        else if (capacityNumber >= 25) color = 'yellow';
                        else color = 'green';

                        statusText += `
                            <div class="server-entry">
                                <span class="server-name">${name}</span>
                                <span class="server-status">${status} (${capacity}%)
                                    <span class="status-indicator" style="background:${color}"></span>
                                </span>
                            </div>
                        `;
                        validServers++;
                    }
                });

                if (validServers > 0) {
                    statusBox.innerHTML = statusText;
                    statusBox.appendChild(buttonContainer);
                } else {
                    statusBox.innerHTML = 'Sunucu bilgisi bulunamadı!';
                    statusBox.appendChild(buttonContainer);
                }
            },
            onerror: function() {
                statusBox.innerHTML = 'Sunucu bilgisi alınamadı!';
                statusBox.appendChild(buttonContainer);
            }
        });
    }


    function changeColor() {
        let colors = ['#FF5733', '#33FF57', '#3357FF', '#F0E68C', '#FF1493'];
        let randomColor = colors[Math.floor(Math.random() * colors.length)];
        statusBox.style.backgroundColor = randomColor;
    }


    fetchServerStatus();
    setInterval(fetchServerStatus, 30000);
})();