Color Switcher v1.1

Color Switcher v1.1 script

当前为 2025-04-05 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Color Switcher v1.1
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Color Switcher v1.1 script
// @author       guildedbird
// @match        pixelplace.io/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    let selectedKey = 'W';
    let autoClickEnabled = false;
    let autoClickInterval = 1000;
    let autoClickTimer = null;
    let uiContainer = null;

    function createUI() {
        uiContainer = document.createElement('ui');
        uiContainer.style.position = 'fixed';
        uiContainer.style.display = 'flex column';
        uiContainer.style.top = '10px';
        uiContainer.style.background = 'rgba(34, 34, 34, 1)';
        uiContainer.style.color = 'white';
        uiContainer.style.padding = '5px';
        uiContainer.style.border = '2.5px solid rgba(0, 226, 255, 1)';
        uiContainer.style.zIndex = '299';
        uiContainer.style.fontFamily = 'monospace';

        let elements = ['name', 'label', 'input', 'br'];
        elements.forEach(tag => {
            let el = document.createElement(tag);
            el.style.fontFamily = 'inherit';
        });

        let nameLabel = document.createElement('name');
        nameLabel.textContent = 'Color Switcher v1';
        nameLabel.style.borderBottom = '2.5px solid rgba(68, 68, 68, 1)';

        let keyLabel = document.createElement('label');
        keyLabel.textContent = 'Set Hotkey:';
        keyLabel.style.fontFamily = 'inherit';

        let keyInput = document.createElement('input');
        keyInput.type = 'text';
        keyInput.value = selectedKey;
        keyInput.maxLength = 1;
        keyInput.style.fontFamily = 'inherit';
        keyInput.style.color = 'rgba(0, 226, 255, 1)';
        keyInput.style.background = 'rgba(10, 10, 10, 1)';
        keyInput.style.width = '8px';
        keyInput.addEventListener('input', function() {
            selectedKey = keyInput.value;
        });

        let autoClickLabel = document.createElement('label');
        autoClickLabel.textContent = 'Auto Switcher';
        autoClickLabel.style.fontFamily = 'inherit';
        let autoClickToggle = document.createElement('input');
        autoClickToggle.type = 'checkbox';
        autoClickToggle.style.fontFamily = 'inherit';
        autoClickToggle.addEventListener('change', function() {
            autoClickEnabled = autoClickToggle.checked;
            toggleAutoClick(autoClickEnabled);
        });

        let intervalLabel = document.createElement('label');
        intervalLabel.textContent = 'Switch Interval:';
        intervalLabel.style.fontFamily = 'inherit';
        let intervalInput = document.createElement('input');
        intervalInput.type = 'number';
        intervalInput.value = autoClickInterval;
        intervalInput.style.fontFamily = 'inherit';
        intervalInput.style.color = 'rgba(0, 226, 255, 1)';
        intervalInput.style.background = 'rgba(10, 10, 10, 1)';
        intervalInput.style.width = '52.5px';
        intervalInput.addEventListener('input', function() {
            autoClickInterval = parseInt(intervalInput.value) || 1000;
            if (autoClickEnabled) {
                toggleAutoClick(false);
                toggleAutoClick(true);
            }
        });

        let hideLabel = document.createElement('label');
        hideLabel.textContent = 'Press Shift to Open/Close';
        hideLabel.style.color = 'rgba(68, 68, 68, 1)';
        hideLabel.style.fontSize = '11px';

        uiContainer.appendChild(nameLabel);
        uiContainer.appendChild(document.createElement('br'));
        uiContainer.appendChild(keyLabel);
        uiContainer.appendChild(keyInput);
        uiContainer.appendChild(document.createElement('br'));
        uiContainer.appendChild(autoClickLabel);
        uiContainer.appendChild(autoClickToggle);
        uiContainer.appendChild(document.createElement('br'));
        uiContainer.appendChild(intervalLabel);
        uiContainer.appendChild(intervalInput);
        uiContainer.appendChild(document.createElement('br'));
        uiContainer.appendChild(hideLabel);

        document.body.appendChild(uiContainer);
    }

    function clickRandomButton() {
        let buttons = document.querySelectorAll('#container #palette-buttons a');
        if (buttons.length > 0) {
            let randomButton = buttons[Math.floor(Math.random() * buttons.length)];
            randomButton.click();
        }
    }

    function toggleAutoClick(enable) {
        if (enable) {
            autoClickTimer = setInterval(clickRandomButton, autoClickInterval);
        } else {
            clearInterval(autoClickTimer);
        }
    }

    document.addEventListener('keydown', function(event) {
        if (event.key === 'Shift') {
            if (uiContainer.style.display === 'none' || !uiContainer.style.display) {
                uiContainer.style.display = 'block'; // Show the UI
            } else {
                uiContainer.style.display = 'none'; // Hide the UI
            }
        }

        if (event.key.toLowerCase() === selectedKey.toLowerCase()) {
            clickRandomButton();
        }
    });

    createUI();
})();

(function() {
    'use strict';

    setTimeout(() => {
        const notifications = document.querySelector('#notification');
        if (!notifications) return;

        const notification = document.createElement('div');
        notification.className = 'box warning pulse-border';
        notification.innerHTML = `
            <div class="icon"></div>
            <div class="content">
                <div class="title">Notice: This is an automation script, do not use this a tool in player/guild wars. Setting the interval below 300 may cause you to become ratelimited. Thank you for using my tool!</div>
            </div>
        `;

        notifications.appendChild(notification);
        setTimeout(() => {
            notification.style.transition = 'opacity 1s';
            notification.style.opacity = '0';
            setTimeout(() => notification.remove(), 1000);
        }, 10000);
    });
    document.querySelector('#container #copyright').innerHTML = "<span style='color: #ffffff;'>Script made by @guildedbird</span>";
    document.querySelector('#container #copyright').style.fontFamily = "monospace";

    const uiMenu = document.querySelector('ui');
    let dragging = false; let initialX; let initialY;

    function md(event) {
        dragging = true;
        initialX = event.clientX - uiMenu.getBoundingClientRect().left; initialY = event.clientY - uiMenu.getBoundingClientRect().top;
        document.body.style.userSelect = 'none';
        document.body.style.cursor = 'move';
    }

    function mm(event) {
        if (dragging) {
            const newX = event.clientX - initialX; const newY = event.clientY - initialY;
            uiMenu.style.left = newX + 'px'; uiMenu.style.top = newY + 'px';
        }
    }

    function mu() {
        dragging = false;
        document.body.style.userSelect = '';
        document.body.style.cursor = '';
    }

    uiMenu.addEventListener('mousedown', md);
    document.addEventListener('mousemove', mm);
    document.addEventListener('mouseup', mu);
})();