Brickplanet Custom Color

Custom Color on BrickPlanet avatar

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Brickplanet Custom Color
// @version      1.0
// @description  Custom Color on BrickPlanet avatar
// @author       Radiohead
// @match        https://www.brickplanet.com/account/avatar/edit
// @grant        none
// @namespace    http://tampermonkey.net/
// ==/UserScript==

(function() {
    'use strict';

    function changeBodyColor(hexCode) {
        const validHex = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
        if (!validHex.test(hexCode)) {
            console.error('Invalid hex code');
            return;
        }
        document.body.style.backgroundColor = hexCode;
    }

    function handleCustomHexColor() {
        const input = document.getElementById('customHexInput');
        const hexCode = input.value.trim();
        if (hexCode) {
            const script = `changeBodyColor('${hexCode}')`;
            console.log(script);
            const scriptElement = document.createElement('script');
            scriptElement.textContent = script;
            document.body.appendChild(scriptElement);
            document.body.removeChild(scriptElement);
        }
    }

    const customColorLink = document.querySelector('a[data-bs-toggle="modal"][data-bs-target="#custom-color"]');
    if (customColorLink) {
        const customHexColorInput = document.createElement('input');
        customHexColorInput.type = 'text';
        customHexColorInput.id = 'customHexInput';
        customHexColorInput.placeholder = 'Enter hex code';

        const applyButton = document.createElement('button');
        applyButton.type = 'button';
        applyButton.innerText = 'Apply';
        applyButton.addEventListener('click', handleCustomHexColor);

        customColorLink.parentNode.appendChild(customHexColorInput);
        customColorLink.parentNode.appendChild(applyButton);
    }
})();