мод, который оптимизирует боевой режим телефонщиков для активного боя и более удобных тренировок
当前为
// ==UserScript==
// @name virtual gamepad
// @namespace http://tampermonkey.net/
// @version 1
// @description мод, который оптимизирует боевой режим телефонщиков для активного боя и более удобных тренировок
// @author кораблекрушение 1198898
// @match https://catwar.net/cw3/*
// @match https://catwar.su/cw3/*
// @match https://catwar.net/settings
// @grant none
// ==/UserScript==
(function () {
'use strict';
const activeKeys = {}; // записывать нажатые клавиши
const keyInUse = {}; // предотвратить многократное срабатывание нажатий
const movementKeys = ['Q', 'W', 'E', 'A', 'S', 'D', 'Z', 'X']; // клавиши передвижения
const actionKeys = ['I', 'J', 'L', 'O']; // клавиши действия
let keyRepeatInterval = {}; // интервал нажатия
let observer; // наблюдатель за DOM
let keyboardEnabled = JSON.parse(localStorage.getItem('virtualKeyboardEnabled')) || false;
// создание
function createVirtualKeyboard() {
if (document.getElementById('virtual-keyboard')) return;
const keyboardHTML = `
<div id="virtual-keyboard">
<div id="left-keys">
<button id="key-Q" class="virtual-key">Q</button>
<button id="key-W" class="virtual-key">W</button>
<button id="key-E" class="virtual-key">E</button>
<button id="key-A" class="virtual-key">A</button>
<button id="key-K" class="virtual-key">K</button>
<button id="key-D" class="virtual-key">D</button>
<button id="key-Z" class="virtual-key">Z</button>
<button id="key-S" class="virtual-key">S</button>
<button id="key-X" class="virtual-key">X</button>
</div>
<div id="right-keys">
<button id="key-I" class="virtual-key">I</button>
<div>
<button id="key-J" class="virtual-key">J</button>
<button id="key-L" class="virtual-key">L</button>
</div>
<button id="key-O" class="virtual-key">O</button>
</div>
</div>
`;
document.body.insertAdjacentHTML('beforeend', keyboardHTML);
const style = document.createElement('style');
style.innerHTML = `
.virtual-key {
width: 150px;
height: 150px;
font-size: 48px;
border: 1px solid #aaa;
border-radius: 10px;
background-color: #eee;
cursor: pointer;
}
.virtual-key:active {
background-color: #ccc;
}
#virtual-keyboard {
position: fixed;
bottom: 20px;
left: 20px;
display: flex;
gap: 20px;
background: rgba(255, 255, 255, 0.9);
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
z-index: 1000;
}
#left-keys {
display: grid;
grid-template-columns: repeat(3, 150px);
grid-template-rows: repeat(3, 150px);
gap: 10px;
justify-items: center;
align-items: center;
}
#right-keys {
position: fixed;
right: 150px;
bottom: 20px;
display: grid;
grid-template-columns: 150px;
grid-template-rows: 150px 150px 150px;
gap: 10px;
justify-items: center;
align-items: center;
margin-top: 20px;
}
#right-keys div {
display: flex;
gap: 10px;
justify-content: center;
}
`;
document.head.appendChild(style);
addKeyboardControls();
}
// удалить
function removeVirtualKeyboard() {
const keyboard = document.getElementById('virtual-keyboard');
if (keyboard) keyboard.remove();
console.log('[Catwar Virtual Keyboard] Виртуальная клавиатура удалена.');
}
// обработчики клавиш
function addKeyboardControls() {
const buttons = document.querySelectorAll('.virtual-key');
buttons.forEach(button => {
button.addEventListener('touchstart', (event) => {
event.preventDefault();
const key = button.id.split('-')[1];
if (!keyInUse[key]) {
keyInUse[key] = true;
activeKeys[key] = true;
simulateKeyEvent('keydown', key);
startKeyRepeat(key);
}
});
button.addEventListener('touchend', (event) => {
event.preventDefault();
const key = button.id.split('-')[1];
if (keyInUse[key]) {
keyInUse[key] = false;
activeKeys[key] = false;
simulateKeyEvent('keyup', key);
stopKeyRepeat(key);
}
});
button.addEventListener('mousedown', () => {
const key = button.id.split('-')[1];
if (!keyInUse[key]) {
keyInUse[key] = true;
activeKeys[key] = true;
simulateKeyEvent('keydown', key);
startKeyRepeat(key);
}
});
button.addEventListener('mouseup', () => {
const key = button.id.split('-')[1];
if (keyInUse[key]) {
keyInUse[key] = false;
activeKeys[key] = false;
simulateKeyEvent('keyup', key);
stopKeyRepeat(key);
}
});
});
}
function startKeyRepeat(key) {
if (keyRepeatInterval[key]) return;
keyRepeatInterval[key] = setInterval(() => {
if (activeKeys[key]) {
simulateKeyEvent('keydown', key);
}
}, 100); // 100 мс между повторениями
}
// остановить повтор для этой клавиши
function stopKeyRepeat(key) {
if (keyRepeatInterval[key]) {
clearInterval(keyRepeatInterval[key]);
delete keyRepeatInterval[key];
}
}
// эмуляция событий клавиатуры
function simulateKeyEvent(type, key) {
const event = new KeyboardEvent(type, {
key: key,
code: `Key${key}`,
keyCode: key.charCodeAt(0),
bubbles: true,
cancelable: true,
});
document.dispatchEvent(event);
console.log(`[DEBUG] Событие ${type} для клавиши: ${key}`);
}
// наблюдение
function observeTooltip() {
observer = new MutationObserver(() => {
const tooltip = document.querySelector('[data-original-title="null"] img[src="actions/28.png"]');
if (tooltip) {
console.log('[Catwar Virtual Keyboard] Элемент найден, создаём клавиатуру.');
if (keyboardEnabled) {
createVirtualKeyboard();
}
} else {
console.log('[Catwar Virtual Keyboard] Элемент отсутствует, удаляем клавиатуру.');
removeVirtualKeyboard();
}
});
observer.observe(document.body, { childList: true, subtree: true });
}
// добавить кнопку включения/выключения в настройки
function addSettings() {
if (document.querySelector('#virtual-keyboard-toggle')) return;
if (window.location.pathname === '/settings') {
const settingsContainer = document.querySelector('.settings-container') || document.body;
const label = document.createElement('label');
label.id = 'virtual-keyboard-toggle';
label.style.display = 'block';
label.style.margin = '10px 0';
label.style.fontSize = '14px';
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.checked = keyboardEnabled;
checkbox.style.marginRight = '5px';
checkbox.addEventListener('change', () => {
keyboardEnabled = checkbox.checked;
localStorage.setItem('virtualKeyboardEnabled', JSON.stringify(keyboardEnabled));
console.log(`[Catwar Virtual Keyboard] виртуальная клавиатура ${keyboardEnabled ? 'включена' : 'выключена'}`);
if (keyboardEnabled) {
createVirtualKeyboard();
} else {
removeVirtualKeyboard();
}
});
label.appendChild(checkbox);
label.appendChild(document.createTextNode('Включить виртуальную клавиатуру'));
settingsContainer.appendChild(label);
}
}
// инициализация
function init() {
console.log('[Catwar Virtual Keyboard] Запуск.');
observeTooltip();
addSettings();
}
//убрать окно "вы никого не ударили"
(function () {
'use strict';
function removeErrorMessage() {
const observer = new MutationObserver(() => {
const errorMessage = document.getElementById('error');
if (errorMessage && errorMessage.innerText.includes("Вы никого не ударили")) {
errorMessage.remove();
console.log('[Catwar Virtual Keyboard] Сообщение об ошибке удалено.');
}
});
observer.observe(document.body, { childList: true, subtree: true });
}
removeErrorMessage();
})();
init();
})();
//объявляется массовый выход из депрессии