Custom Background Changer

Плавающие кнопки для смены фона: предустановки, своё изображение, сброс.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Custom Background Changer
// @namespace    https://bigbaazi-onlinecasino.com
// @version      2.0
// @license      MIT
// @description  Плавающие кнопки для смены фона: предустановки, своё изображение, сброс.
// @author       User
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // ─── Конфигурация ───────────────────────────────────────────────────────────

    const STORAGE_KEY = 'customBgStyle';

    const PRESETS = [
        { name: 'Белый',              style: '#ffffff' },
        { name: 'Серый',              style: '#e0e0e0' },
        { name: 'Пастельный синий',   style: '#b8e1fc' },
        { name: 'Мятный',             style: '#b9f6ca' },
        { name: 'Градиент — закат',   style: 'linear-gradient(135deg, #ff9a9e, #fad0c4)' },
        { name: 'Градиент — ночь',    style: 'linear-gradient(135deg, #2c3e50, #000000)' },
    ];

    // ─── Применение фона ────────────────────────────────────────────────────────

    function applyBackground(style) {
        document.body.style.background           = style;
        document.body.style.backgroundSize       = 'cover';
        document.body.style.backgroundAttachment = 'fixed';
        localStorage.setItem(STORAGE_KEY, style);
    }

    function resetBackground() {
        document.body.style.background           = '';
        document.body.style.backgroundSize       = '';
        document.body.style.backgroundAttachment = '';
        localStorage.removeItem(STORAGE_KEY);
    }

    // ─── Фабрика кнопок ─────────────────────────────────────────────────────────

    function createButton({ label, color, rightOffset }) {
        const btn = document.createElement('button');
        btn.textContent = label;
        Object.assign(btn.style, {
            position:        'fixed',
            bottom:          '20px',
            right:           `${rightOffset}px`,
            zIndex:          '9999',
            padding:         '8px 16px',
            backgroundColor: color,
            color:           'white',
            border:          'none',
            borderRadius:    '20px',
            cursor:          'pointer',
            fontFamily:      'sans-serif',
            fontSize:        '14px',
            boxShadow:       '0 2px 10px rgba(0,0,0,0.3)',
            transition:      'opacity 0.2s',
        });
        btn.addEventListener('mouseover', () => { btn.style.opacity = '0.85'; });
        btn.addEventListener('mouseout',  () => { btn.style.opacity = '1'; });
        document.body.appendChild(btn);
        return btn;
    }

    // ─── Кнопка «Сменить фон» ───────────────────────────────────────────────────

    let currentIndex = 0;

    const cycleBtn = createButton({
        label:       '🎨 Сменить фон',
        color:       '#2c3e50',
        rightOffset: 20,
    });

    cycleBtn.addEventListener('click', () => {
        currentIndex = (currentIndex + 1) % PRESETS.length;
        const { name, style } = PRESETS[currentIndex];
        applyBackground(style);
        cycleBtn.textContent = `🎨 ${name}`;
    });

    // ─── Кнопка «Своё фото» ─────────────────────────────────────────────────────

    const fileInput = Object.assign(document.createElement('input'), {
        type:   'file',
        accept: 'image/*',
    });
    fileInput.style.display = 'none';
    document.body.appendChild(fileInput);

    const uploadBtn = createButton({
        label:       '📷 Своё фото',
        color:       '#27ae60',
        rightOffset: 155,
    });

    uploadBtn.addEventListener('click', () => fileInput.click());

    fileInput.addEventListener('change', () => {
        const file = fileInput.files[0];
        if (!file) return;
        const reader = new FileReader();
        reader.onload = ({ target }) => {
            const style = `url(${target.result}) no-repeat center center`;
            applyBackground(style);
            cycleBtn.textContent = '🎨 Свой фон';
        };
        reader.readAsDataURL(file);
    });

    // ─── Кнопка «Сброс» ─────────────────────────────────────────────────────────

    const resetBtn = createButton({
        label:       '✖ Сброс',
        color:       '#c0392b',
        rightOffset: 275,
    });

    resetBtn.addEventListener('click', () => {
        resetBackground();
        currentIndex = 0;
        cycleBtn.textContent = '🎨 Сменить фон';
    });

    // ─── Восстановление последнего фона ─────────────────────────────────────────

    const savedStyle = localStorage.getItem(STORAGE_KEY);
    if (savedStyle) {
        applyBackground(savedStyle);
        const matchedIndex = PRESETS.findIndex(p => p.style === savedStyle);
        if (matchedIndex !== -1) {
            currentIndex = matchedIndex;
            cycleBtn.textContent = `🎨 ${PRESETS[currentIndex].name}`;
        } else {
            cycleBtn.textContent = '🎨 Свой фон';
        }
    }

})();