Agar.io Custom Skin Border (Only via Game System)

Subir imagen como skin sin modificarla, aplicando borde con el sistema del juego. Color 1=blanco, Color 2=negro.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Agar.io Custom Skin Border (Only via Game System)
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Subir imagen como skin sin modificarla, aplicando borde con el sistema del juego. Color 1=blanco, Color 2=negro.
// @author       OpenAI - Personalizado
// @match        *://agar.io/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    const waitForElement = (selector, callback) => {
        const interval = setInterval(() => {
            const element = document.querySelector(selector);
            if (element) {
                clearInterval(interval);
                callback(element);
            }
        }, 500);
    };

    waitForElement('#canvas', () => {
        const observer = new MutationObserver(() => {
            const saveBtn = document.querySelector('.btn.btn-success[onclick*="save"]');
            const existingUpload = document.getElementById('custom-skin-upload');

            if (saveBtn && !existingUpload) {
                const uploadInput = document.createElement('input');
                uploadInput.type = 'file';
                uploadInput.accept = 'image/*';
                uploadInput.style.marginRight = '10px';
                uploadInput.id = 'custom-skin-upload';

                uploadInput.addEventListener('change', async function () {
                    const file = this.files[0];
                    if (!file) return;

                    const reader = new FileReader();
                    reader.onload = function (e) {
                        const imageData = e.target.result;
                        localStorage.setItem('customSkinImage', imageData);
                        alert('✅ Imagen cargada. Ahora presiona "Save" para aplicar la skin.');
                    };
                    reader.readAsDataURL(file);
                });

                saveBtn.parentNode.insertBefore(uploadInput, saveBtn);
            }
        });

        observer.observe(document.body, { childList: true, subtree: true });
    });

    // Hookear la función Save para aplicar la skin con borde del sistema
    const originalSetItem = localStorage.setItem;
    localStorage.setItem = function (key, value) {
        if (key === 'selectedColor') {
            const colorNum = parseInt(value);
            if (colorNum === 1) {
                value = '#FFFFFF'; // blanco
            } else if (colorNum === 2) {
                value = '#000000'; // negro
            }
        }
        return originalSetItem.apply(this, [key, value]);
    };

    // Aplicar la imagen cargada cuando se haga clic en Save
    document.addEventListener('click', function (e) {
        if (e.target && e.target.matches('.btn.btn-success[onclick*="save"]')) {
            const imgData = localStorage.getItem('customSkinImage');
            if (imgData) {
                localStorage.setItem('customSkin', imgData);
                alert('✅ Skin personalizada aplicada con borde del sistema.');
            }
        }
    });
})();