Polytoria Hex Input

Adds a Hex input to the advanced color picker.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name Polytoria Hex Input
// @version 1.5
// @description Adds a Hex input to the advanced color picker.
// @author Eave
// @match *://polytoria.com/my/avatar*
// @run-at document-start
// @grant none
// @license MIT
// @namespace https://greasyfork.org/users/1567372
// ==/UserScript==

(function() {
    'use strict';

    let activePicker = null;

    const observeIro = () => {
        if (window.iro && !window.iro._hooked) {
            const OriginalPicker = window.iro.ColorPicker;
            window.iro.ColorPicker = function(el, opts) {
                const instance = new OriginalPicker(el, opts);
                activePicker = instance;

                instance.on('color:change', (color) => {
                    const input = document.getElementById('hex-input');
                    if (input && document.activeElement !== input) {
                        input.value = color.hexString.toUpperCase();
                    }
                });
                return instance;
            };
            window.iro._hooked = true;
        }
    };

    const injectUI = () => {
        const container = document.querySelector('.wheel-container');
        if (!container || document.getElementById('hex-input')) return;

        container.style.display = 'flex';
        container.style.flexDirection = 'column';
        container.style.alignItems = 'center';

        const hexInput = document.createElement('input');
        hexInput.id = 'hex-input';
        hexInput.type = 'text';
        hexInput.maxLength = 7;
        hexInput.placeholder = '#FFFFFF';

        Object.assign(hexInput.style, {
            width: '200px',
            marginTop: '15px',
            padding: '10px',
            backgroundColor: '#1b1b1b',
            border: '1px solid #323232',
            color: '#ffffff',
            textAlign: 'center',
            borderRadius: '8px',
            fontSize: '14px',
            fontWeight: '600',
            outline: 'none',
            transition: 'border-color 0.2s ease',
            boxSizing: 'border-box',
            display: 'block'
        });

        hexInput.onfocus = () => hexInput.style.borderColor = '#3b82f6';
        hexInput.onblur = () => hexInput.style.borderColor = '#323232';

        hexInput.addEventListener('input', (e) => {
            const val = e.target.value;

            const hexRegex = /^#?[0-9A-Fa-f]{6}$/;

            if (hexRegex.test(val) && activePicker) {
                const formattedHex = val.startsWith('#') ? val : '#' + val;
                try {activePicker.color.set(formattedHex);} catch (err) {}
            }
        });

        container.appendChild(hexInput);
    };

    setInterval(() => {
        observeIro();
        injectUI();
    }, 500);
})();