Agar.io custom skin upload to skin

Upload image for custom skin

2023-04-27 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Agar.io custom skin upload to skin
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Upload image for custom skin
// @author       New Jack 🕹️
// @match        agar.io/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    function createButton() {
        const button = document.createElement("input");
        button.type = "file";
        button.accept = "image/*";
        button.id = "customImageUpload";
        return button;
    }

    function insertButton(button, target) {
        if (target) {
            target.appendChild(button);
        }
    }

    function convertImageToBase64(event) {
        const file = event.target.files[0];
        const reader = new FileReader();

        reader.onloadend = function () {
            const base64 = reader.result;
            drawImage(base64);
        };

        reader.readAsDataURL(file);
    }

    function drawImage(base64) {
        const c = document.getElementById("skin-editor-canvas");
        const ctx = c.getContext("2d");
        const image = new Image();

        image.onload = function () {
            // Set the canvas size to 512x512
            c.width = 512;
            c.height = 512;

            // Draw the image on the canvas, resizing it to 512x512
            ctx.drawImage(image, 0, 0, 512, 512);
            ctx.save();
        };

        image.src = base64;
    }

    function checkForRightTools() {
        const rightTools = document.querySelector(".right-tools");

        if (rightTools) {
            const button = createButton();
            insertButton(button, rightTools);
            button.addEventListener("change", convertImageToBase64);

            // Clear the interval once the button is added.
            clearInterval(checkInterval);
        }
    }

    // Check for the .right-tools element every 5 seconds (5000 milliseconds).
    const checkInterval = setInterval(checkForRightTools, 5000);
})();