// ==UserScript==
// @name PCOL-ASSIST
// @author 葉月Hikaru
// @match http://www.heyzxz.me/pcol/*
// @version 2.0
// @namespace https://gf.qytechs.cn/users/your-id
// @description 为http://www.heyzxz.me/pcol/添加虚拟按键
// ==/UserScript==
(function() {
'use strict';
// 按键配置(修改option键为触发alt,文本显示为action)
const keysConfig = [
// W键左右侧滚轮键(文本互换)
{ 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 },
// C键正下方P键
{ 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 },
// A键左侧option键(修改为触发alt键,文本显示为action)
{ key: 'Alt', text: 'action', top: 120, left: 20 }
];
// 创建按键函数
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;
`;
// 模拟按键事件(option键改为触发alt)
function triggerKeyEvent(type) {
if (keyConfig.key === '+' || keyConfig.key === '-') {
// 滚轮事件(文本互换功能不变)
const wheelEvent = new WheelEvent('wheel', {
deltaY: keyConfig.key === '+' ? -300 : 300,
bubbles: true,
cancelable: true
});
const gameCanvas = document.querySelector('canvas');
gameCanvas?.dispatchEvent(wheelEvent) || document.dispatchEvent(wheelEvent);
} else if (keyConfig.key === 'Alt') {
// 修改为触发alt键
const altEvent = new KeyboardEvent(type, {
key: 'Alt', code: 'AltLeft', keyCode: 18,
bubbles: true, cancelable: true
});
document.dispatchEvent(altEvent);
} 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
});
const gameCanvas = document.querySelector('canvas');
gameCanvas?.dispatchEvent(event) || document.dispatchEvent(event);
}
}
// 绑定事件
['touchstart', 'mousedown'].forEach(e => btn.addEventListener(e, e => {
e.preventDefault();
triggerKeyEvent('keydown');
}));
['touchend', 'mouseup'].forEach(e => btn.addEventListener(e, e => {
e.preventDefault();
triggerKeyEvent('keyup');
}));
document.body.appendChild(btn);
}
// 延迟初始化
setTimeout(() => {
keysConfig.forEach(createVirtualKey);
console.log('【PCOL-ASSIST】已修改option键为alt功能,显示文本为"action"');
}, 500);
})();