PCOL-ASSIST-iOS

为iOS平板优化,添加Alt+拖拽滑动区域

目前為 2025-07-02 提交的版本,檢視 最新版本

// ==UserScript==
// @name         PCOL-ASSIST-iOS
// @author       葉月Hikaru
// @match        http://www.heyzxz.me/pcol/*
// @version 5.1
// @namespace https://gf.qytechs.cn/users/your-id
// @description 为iOS平板优化,添加Alt+拖拽滑动区域
// ==/UserScript==

(function() {
    'use strict';

    // 基础按键配置(保留原有功能)
    const keysConfig = [
        { key: '+', text: '-', top: 30, left: 40 },
        { key: 'w', text: 'W', top: 30, left: 50 },
        { key: '-', text: '+', top: 30, left: 60 },
        { key: 'space', text: 'SPACE', top: 30, left: 70 },
        { key: 'x', text: 'X', top: 30, left: 80 },
        { key: 'c', text: 'C', top: 30, left: 90 },
        { key: 'p', text: 'P', top: 120, left: 90 },
        { key: 'a', text: 'A', top: 120, left: 30 },
        { key: 's', text: 'S', top: 120, left: 50 },
        { key: 'd', text: 'D', top: 120, left: 70 }
    ];

    // 创建基础按键(保持原有逻辑)
    function createVirtualKey(keyConfig) {
        const btn = document.createElement('button');
        btn.id = `pcol-assist-${keyConfig.key}-btn`;
        btn.textContent = keyConfig.text;
        btn.style.cssText = `
            position: fixed;
            top: ${keyConfig.top}px;
            left: ${keyConfig.left}%;
            transform: ${keyConfig.left === 50 ? 'translateX(-50%)' : 'translateX(0)'};
            width: 60px;
            height: 60px;
            font-size: ${keyConfig.text === 'SPACE' ? '16px' : '28px'};
            background-color: rgba(255, 165, 0, 0.9);
            color: white;
            border: 2px solid white;
            border-radius: 50%;
            cursor: pointer;
            z-index: 9999;
        `;

        function triggerEvent(type) {
            if (keyConfig.key === '+' || keyConfig.key === '-') {
                const wheelEvent = new WheelEvent('wheel', {
                    deltaY: keyConfig.key === '+' ? -300 : 300,
                    bubbles: true,
                    cancelable: true
                });
                document.querySelector('canvas')?.dispatchEvent(wheelEvent) || document.dispatchEvent(wheelEvent);
            } else {
                const key = keyConfig.key === 'space' ? ' ' : keyConfig.key;
                const event = new KeyboardEvent(type, {
                    key: key === ' ' ? 'Spacebar' : key,
                    code: key === ' ' ? 'Space' : `Key${key.toUpperCase()}`,
                    keyCode: key === 'w' ? 87 : key === 'a' ? 65 : key === 's' ? 83 : 
                           key === 'd' ? 68 : key === 'x' ? 88 : key === 'c' ? 67 : key === 'p' ? 80 : 32,
                    bubbles: true,
                    cancelable: true
                });
                document.querySelector('canvas')?.dispatchEvent(event) || document.dispatchEvent(event);
            }
        }

        ['touchstart', 'mousedown'].forEach(e => btn.addEventListener(e, e => {
            e.preventDefault();
            triggerEvent('keydown');
        }));
        ['touchend', 'mouseup'].forEach(e => btn.addEventListener(e, e => {
            e.preventDefault();
            triggerEvent('keyup');
        }));

        document.body.appendChild(btn);
    }

    // 创建Alt+拖拽滑动区域
    function createDragArea() {
        const area = document.createElement('div');
        area.id = 'pcol-drag-area';
        area.textContent = 'Alt+拖拽';
        area.style.cssText = `
            position: fixed;
            bottom: 50px;
            right: 20px;
            width: 200px;
            height: 200px;
            background-color: rgba(0, 128, 255, 0.7);  /* 改为蓝色背景 */
            color: white;
            border-radius: 10px;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 16px;
            cursor: move;
            z-index: 9999;
        `;

        // 触摸状态标记
        let isTouching = false;
        let lastX = 0, lastY = 0;

        // 模拟Alt键按下
        function startAltPress() {
            const altEvent = new KeyboardEvent('keydown', {
                key: 'Alt', code: 'AltLeft', keyCode: 18,  /* 改为Alt键参数 */
                bubbles: true, cancelable: true
            });
            document.dispatchEvent(altEvent);
        }

        // 模拟Alt键松开
        function endAltPress() {
            const altEvent = new KeyboardEvent('keyup', {
                key: 'Alt', code: 'AltLeft', keyCode: 18,   /* 改为Alt键参数 */
                bubbles: true, cancelable: true
            });
            document.dispatchEvent(altEvent);
        }

        // 模拟鼠标移动事件(逻辑不变)
        function simulateMouseDrag(x, y) {
            const mouseEvent = new MouseEvent('mousemove', {
                clientX: x,
                clientY: y,
                bubbles: true,
                cancelable: true
            });
            document.dispatchEvent(mouseEvent);
        }

        // 触摸事件绑定(逻辑不变)
        area.addEventListener('touchstart', e => {
            e.preventDefault();
            isTouching = true;
            startAltPress();  /* 改为触发Alt键按下 */
            const touch = e.touches[0];
            lastX = touch.clientX;
            lastY = touch.clientY;
        });

        area.addEventListener('touchmove', e => {
            if (!isTouching) return;
            e.preventDefault();
            const touch = e.touches[0];
            const dx = touch.clientX - lastX;
            const dy = touch.clientY - lastY;
            lastX = touch.clientX;
            lastY = touch.clientY;
            
            const canvas = document.querySelector('canvas');
            if (canvas) {
                const rect = canvas.getBoundingClientRect();
                const canvasX = touch.clientX - rect.left;
                const canvasY = touch.clientY - rect.top;
                simulateMouseDrag(canvasX, canvasY);
            }
        });

        area.addEventListener('touchend', e => {
            e.preventDefault();
            isTouching = false;
            endAltPress();  /* 改为触发Alt键松开 */
        });

        area.addEventListener('touchcancel', e => {
            e.preventDefault();
            isTouching = false;
            endAltPress();
        });

        document.body.appendChild(area);
    }

    // 初始化
    setTimeout(() => {
        keysConfig.forEach(createVirtualKey);
        createDragArea();
        console.log('【PCOL-ASSIST】iOS优化版已加载,新增Alt+拖拽滑动区域');
    }, 500);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址