Polytoria Hex Input

Adds a Hex input to the advanced color picker.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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);
})();