RGB Palitra dlya Zelenka.guru

RGB Палитра для Zelenka.guru

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         RGB Palitra dlya Zelenka.guru
// @namespace    https://zelenka.guru/p_gr/ | Wi33y
// @version      6.5
// @description  RGB Палитра для Zelenka.guru
// @author       Your Name
// @match        https://zelenka.guru/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Создаем контейнер для кнопок
    const container = document.createElement('div');
    container.style.display = 'inline-block'; //  inline-block
    container.style.verticalAlign = 'middle'; // Выравниваем
    container.style.marginTop = '5px'; //

    // Создаем кнопку "Выбрать цвет" с иконкой
    const colorButton = createButton('Выбрать цвет', 'fal fa-paint-brush', '#222', toggleColorMenu);

    // Создаем кнопку "Применить цвет" с иконкой
    const applyButton = createButton('Применить цвет', 'fal fa-check', '#222', applyColor);

    // Создаем меню выбора RGB цвета
    const rgbColorMenu = document.createElement('input');
    rgbColorMenu.type = 'color'; //
    rgbColorMenu.style.zIndex = '9999';
    rgbColorMenu.style.display = 'none'; //
    rgbColorMenu.style.left = 'calc(100% + 10px)'; //
    rgbColorMenu.style.top = '0'; //

    // Добавляем кнопки "Выбрать цвет" и "Применить цвет" в контейнер
    container.appendChild(colorButton);
    container.appendChild(applyButton);

    // Добавляем контейнер в контейнер редактора
    const editorToolbar = document.querySelector('.fr-toolbar');
    if (editorToolbar) {
        editorToolbar.appendChild(container);
        editorToolbar.appendChild(rgbColorMenu); //

        colorButton.addEventListener('click', toggleColorMenu);
    }

    // Функция для создания кнопки с заданными параметрами
    function createButton(text, iconClass, bgColor, clickHandler) {
        const button = document.createElement('span');
        button.style.padding = '3px 8px'; //
        button.style.backgroundColor = bgColor; //
        button.style.borderRadius = '4px';
        button.style.cursor = 'pointer';
        button.style.lineHeight = '1'; //
        button.style.color = 'white'; //
        button.style.display = 'inline-block'; //
        button.style.verticalAlign = 'middle'; //

        // Создаем иконку для кнопки
        const icon = document.createElement('i');
        icon.className = iconClass; //
        icon.style.marginRight = '3px'; //

        button.appendChild(icon);
        button.appendChild(document.createTextNode(text));

        button.addEventListener('click', clickHandler);

        return button;
    }

    // Функция для переключения видимости меню выбора цвета
    function toggleColorMenu() {
        if (rgbColorMenu.style.display === 'none' || rgbColorMenu.style.display === '') {
            rgbColorMenu.style.display = 'block';
        } else {
            rgbColorMenu.style.display = 'none';
        }
    }

    // Функция для применения цвета к выделенному тексту
    function applyColor() {
        const selection = window.getSelection();
        if (selection.rangeCount > 0) {
            const range = selection.getRangeAt(0);
            const span = document.createElement('span');
            span.style.color = rgbColorMenu.value;
            range.surroundContents(span);
        }
        rgbColorMenu.style.display = 'none'; //
    }
})();