Coconut Shy Keyboard Controls

Adds simple keybinds for Coconut Shy

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Coconut Shy Keyboard Controls
// @namespace    zooops
// @version      1.0
// @description  Adds simple keybinds for Coconut Shy
// @author       mox & Z
// @match        https://www.grundos.cafe/halloween/coconutshy*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=grundos.cafe
// @license      MIT
// @grant        none
// ==/UserScript==

// code by mox for a larger project that's on hold, but with the release of the coconut shy avatar, I've decided to publish it standalone for now!
// (if you read the code you'll notice that it's meant to work for TYS too, but it's not working for that one and ngl I don't know how to debug it)

window.addEventListener("keydown", (event) => {
    if(event.target.matches("input[type='text']")) {return;} //if entering text in a text box, don't record keydown event
    let arrowKeyCount = 0;
    let digitKeyCount = 0; //initialize some useful variables
    var canvas = document.querySelector("canvas"); //see if there's a canvas-type element on the page (e.g. strtest, coconutshy)
    switch (event.code) {
        case "Space":
            event.preventDefault(); //falls through so Space can be used like Enter
        case "Enter": //falls through so either Enter key can be used interchangeably
        case "NumpadEnter":
            if (location.pathname.match(/coconutshy|strtest/)) {
                if (canvas) {
                    var clientRect = canvas.getBoundingClientRect();
                    var pX = clientRect.left;
                    var pY = clientRect.top;
                    var clickEvent;
                    if (location.pathname.match(/coconutshy/)) {
                        pX += 250; pY += 330;
                    } else if (location.pathname.match(/strtest/)) {
                        pX += 150; pY += 160;
                        clickEvent = new MouseEvent("mousemove",{
                            clientX: pX, clientY: pY, bubbles: true });
                        canvas.dispatchEvent(clickEvent);
                    }
                    clickEvent = new MouseEvent("mousedown",{
                        clientX: pX, clientY: pY, bubbles: true, buttons: 1 });
                    canvas.dispatchEvent(clickEvent);
                }
                if (document.querySelector('#modal-body[style="padding: 10px;"]')) {location.reload();}
            } break;
    }
 });