-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat-enhancer.user.js
More file actions
50 lines (38 loc) · 1.49 KB
/
Copy pathchat-enhancer.user.js
File metadata and controls
50 lines (38 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// ==UserScript==
// @name TagPro Chat Enhancer
// @version 0.1.2
// @description Chat enhancer. So far, it will just allow you to move with arrow keys whilst typing a message.
// @author Zagd
// @downloadURL https://github.com/zagd/tagpro-scripts/raw/master/chat-enhancer.user.js
// @updateURL https://github.com/zagd/tagpro-scripts/raw/master/chat-enhancer.user.js
// @include *://tagpro.koalabeast.com/game
// @include *://tagpro.koalabeast.com/game?*
// @include *://*.newcompte.fr:*
// @include *://tagpro-maptest.koalabeast.com:*
// ==/UserScript==
const PLAYABLE_STATES = [1, 5];
const handleKey = e => {
if (!tagpro.disableControls) return;
const { key } = e;
const isArrow = ["ArrowUp", "ArrowRight", "ArrowDown", "ArrowLeft"].includes(key);
if (!isArrow) return;
const dir = key.match(/Arrow(.*)/)[1].toLowerCase();
const isPressing = e.type === "keydown";
tagpro.players[tagpro.playerId].pressing[dir] !== isPressing && tagpro.sendKeyPress(dir, !isPressing);
};
const start = () => {
addEventListener("keydown", handleKey);
addEventListener("keyup", handleKey);
};
const stop = () => {
removeEventListener("keydown", handleKey);
removeEventListener("keyup", handleKey);
};
tagpro.ready(() => {
if (PLAYABLE_STATES.includes(tagpro.state)) {
start();
} else {
tagpro.socket.on("time", ({ state }) => PLAYABLE_STATES.includes(state) && start());
}
tagpro.socket.on("end", stop);
});