Drawaria Персональный Помощник

Помощник с загрузкой фото и автономными записками

// ==UserScript==
// @name         Drawaria Персональный Помощник
// @namespace    http://tampermonkey.net/
// @version      2.2
// @description  Помощник с загрузкой фото и автономными записками
// @author       YourName
// @match        https://drawaria.online/*
// @match        https://www.drawaria.online/*
// @grant        GM_addStyle
// @grant        GM_getValue
// @grant        GM_setValue
// ==/UserScript==

(function() {
    'use strict';

    // Стили
    GM_addStyle(`
        #drawaria-assistant {
            position: fixed;
            width: 120px;
            height: 120px;
            background-size: contain;
            background-repeat: no-repeat;
            cursor: grab;
            z-index: 9999;
            user-select: none;
            pointer-events: auto;
            transition: transform 0.2s;
        }

        #drawaria-assistant.dragging {
            cursor: grabbing;
            transform: scale(1.1);
        }

        .assistant-message {
            position: absolute;
            bottom: 125%;
            left: 50%;
            transform: translateX(-50%);
            background-color: #fff9c4;
            padding: 8px 12px;
            border-radius: 12px;
            box-shadow: 0 3px 10px rgba(0,0,0,0.2);
            font-family: 'Comic Sans MS', cursive;
            font-size: 14px;
            max-width: 200px;
            text-align: center;
            border: 2px solid #ffd700;
            opacity: 0;
            transition: opacity 0.3s;
            pointer-events: none;
        }

        #drawaria-assistant:hover .assistant-message {
            opacity: 1;
        }

        #assistant-controls {
            position: fixed;
            bottom: 20px;
            right: 20px;
            z-index: 10000;
            background: white;
            padding: 10px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.2);
        }

        #upload-assistant-btn {
            background: #4CAF50;
            color: white;
            border: none;
            padding: 8px 12px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
        }

        #assistant-image-input {
            display: none;
        }

        .note-from-assistant {
            position: fixed;
            background: #fff9c4;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 4px 15px rgba(0,0,0,0.2);
            border: 2px solid #ffd700;
            max-width: 250px;
            z-index: 10001;
            display: none;
            animation: noteAppear 0.5s;
            text-align: center;
        }

        @keyframes noteAppear {
            from { transform: scale(0.5); opacity: 0; }
            to { transform: scale(1); opacity: 1; }
        }

        .note-close {
            position: absolute;
            top: 5px;
            right: 5px;
            cursor: pointer;
            font-weight: bold;
            font-size: 18px;
        }
    `);

    // Создаем помощника
    const assistant = document.createElement('div');
    assistant.id = 'drawaria-assistant';

    // Сообщение при наведении
    const message = document.createElement('div');
    message.className = 'assistant-message';
    message.textContent = 'Я ваш помощник!';
    assistant.appendChild(message);

    document.body.appendChild(assistant);

    // Панель управления (только загрузка фото)
    const controlsPanel = document.createElement('div');
    controlsPanel.id = 'assistant-controls';

    const uploadButton = document.createElement('button');
    uploadButton.id = 'upload-assistant-btn';
    uploadButton.textContent = 'Загрузить фото';

    const fileInput = document.createElement('input');
    fileInput.type = 'file';
    fileInput.id = 'assistant-image-input';
    fileInput.accept = 'image/*';

    controlsPanel.appendChild(uploadButton);
    controlsPanel.appendChild(fileInput);
    document.body.appendChild(controlsPanel);

    // Записка от помощника
    const note = document.createElement('div');
    note.className = 'note-from-assistant';
    note.innerHTML = `
        <span class="note-close">&times;</span>
        <div class="note-content"></div>
    `;
    document.body.appendChild(note);

    // Настройки помощника
    let posX = Math.random() * (window.innerWidth - 120);
    let posY = Math.random() * (window.innerHeight - 120);
    let targetX = posX;
    let targetY = posY;
    let speed = 0.5 + Math.random() * 2;
    let isDragging = false;
    let dragOffsetX = 0;
    let dragOffsetY = 0;
    let lastNoteTime = 0;

    const notes = [
        "Не забывайте сохранять работу!",
        "Попробуйте новый инструмент сегодня!",
        "Вы великолепный художник!",
        "Сделайте перерыв, если устали!",
        "Как насчет попробовать новый цвет?",
        "Ваш прогресс впечатляет!",
        "Рисуйте с удовольствием!",
        "Сегодня отличный день для творчества!",
        "Не бойтесь экспериментировать!",
        "Вы делаете это просто прекрасно!"
    ];

    // Загружаем сохраненное изображение
    const savedImage = GM_getValue('assistantImage', '');
    if (savedImage) {
        assistant.style.backgroundImage = `url('${savedImage}')`;
    } else {
        assistant.style.backgroundImage = 'url("https://i.imgur.com/469d84f081bf628c4573a40792f8a519.png")';
    }

    // Позиционируем помощника
    assistant.style.left = posX + 'px';
    assistant.style.top = posY + 'px';

    // Движение помощника
    function moveAssistant() {
        if (isDragging) {
            requestAnimationFrame(moveAssistant);
            return;
        }

        const now = Date.now();

        // Случайно меняем направление
        if (Math.random() < 0.005 || now - lastMoveTime > 10000) {
            targetX = Math.random() * (window.innerWidth - 120);
            targetY = Math.random() * (window.innerHeight - 120);
            speed = 0.5 + Math.random() * 2;
            lastMoveTime = now;
        }

        // Двигаемся к цели
        const dx = targetX - posX;
        const dy = targetY - posY;
        const distance = Math.sqrt(dx * dx + dy * dy);

        if (distance > 5) {
            posX += (dx / distance) * speed;
            posY += (dy / distance) * speed;
        }

        // Границы экрана
        posX = Math.max(0, Math.min(window.innerWidth - 120, posX));
        posY = Math.max(0, Math.min(window.innerHeight - 120, posY));

        // Применяем движение
        assistant.style.left = posX + 'px';
        assistant.style.top = posY + 'px';

        // Отражаем изображение
        assistant.style.transform = dx < 0 ? 'scaleX(-1)' : 'scaleX(1)';

        // Проверяем, не пора ли принести записку
        if (now - lastNoteTime > 120000 + Math.random() * 180000) {
            deliverNote();
            lastNoteTime = now;
        }

        requestAnimationFrame(moveAssistant);
    }

    function deliverNote() {
        // Подлетаем к пользователю
        targetX = window.innerWidth / 2 - 60;
        targetY = window.innerHeight / 2 - 60;
        speed = 3;

        // Показываем записку через 2 секунды
        setTimeout(() => {
            const noteContent = note.querySelector('.note-content');
            noteContent.textContent = notes[Math.floor(Math.random() * notes.length)];

            note.style.left = (posX + 140) + 'px';
            note.style.top = (posY - 50) + 'px';
            note.style.display = 'block';

            // Закрытие записки
            note.querySelector('.note-close').onclick = () => {
                note.style.display = 'none';
            };

            // Автоматическое закрытие через 10 секунд
            setTimeout(() => {
                if (note.style.display !== 'none') {
                    note.style.display = 'none';
                }
            }, 10000);
        }, 2000);
    }

    // Загрузка изображения
    uploadButton.addEventListener('click', () => fileInput.click());
    fileInput.addEventListener('change', function(e) {
        const file = e.target.files[0];
        if (file) {
            const reader = new FileReader();
            reader.onload = function(event) {
                const imageUrl = event.target.result;
                assistant.style.backgroundImage = `url('${imageUrl}')`;
                GM_setValue('assistantImage', imageUrl);
                message.textContent = "Теперь я выгляжу лучше!";
                message.style.opacity = '1';
                setTimeout(() => message.style.opacity = '0', 3000);
            };
            reader.readAsDataURL(file);
        }
    });

    // Перетаскивание помощника
    assistant.addEventListener('mousedown', function(e) {
        isDragging = true;
        dragOffsetX = e.clientX - posX;
        dragOffsetY = e.clientY - posY;
        assistant.classList.add('dragging');
        message.textContent = "Отпустите меня где угодно!";
        message.style.opacity = '1';
        e.preventDefault();
    });

    document.addEventListener('mousemove', function(e) {
        if (isDragging) {
            posX = e.clientX - dragOffsetX;
            posY = e.clientY - dragOffsetY;
            posX = Math.max(0, Math.min(window.innerWidth - 120, posX));
            posY = Math.max(0, Math.min(window.innerHeight - 120, posY));
            assistant.style.left = posX + 'px';
            assistant.style.top = posY + 'px';
        }
    });

    document.addEventListener('mouseup', function() {
        if (isDragging) {
            isDragging = false;
            assistant.classList.remove('dragging');
            setTimeout(() => message.style.opacity = '0', 2000);
        }
    });

    // Простое сообщение при клике
    assistant.addEventListener('click', function(e) {
        e.stopPropagation();
        message.textContent = "Чем могу помочь?";
        message.style.opacity = '1';
        setTimeout(() => message.style.opacity = '0', 3000);
    });

    // Реакция на изменение размера окна
    window.addEventListener('resize', function() {
        posX = Math.max(0, Math.min(window.innerWidth - 120, posX));
        posY = Math.max(0, Math.min(window.innerHeight - 120, posY));
        assistant.style.left = posX + 'px';
        assistant.style.top = posY + 'px';
    });

    // Запускаем помощника
    let lastMoveTime = Date.now();
    moveAssistant();
})();