GC - Pick Your Own - Keyboard Controls

Add keyboard navigation to GC's Pick Your Own.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         GC - Pick Your Own - Keyboard Controls
// @namespace    https://greasyfork.org/en/users/1175371
// @version      0.4
// @description  Add keyboard navigation to GC's Pick Your Own.
// @author       sanjix
// @match        https://www.grundos.cafe/medieval/pickyourown/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=grundos.cafe
// @grant        none
// @license      MIT
// ==/UserScript==

var start = document.querySelector('input[value="Click to Play!"]');
var left = document.querySelector('input#pyo-left-arrow');
var right = document.querySelector('input#pyo-right-arrow');
var up = document.querySelector('input#pyo-up-arrow');
var down = document.querySelector('input#pyo-down-arrow');
var map = document.querySelector('form[action="/medieval/process_pickyourown/?pick=1"] input[type="image"]');
var collect = document.querySelector('input[value="Collect Berries and Leave Farm"]');

document.addEventListener("keydown", ((event) => {
    switch (event.keyCode) {
        case 38: //up-arrow
        case 87: //w
            {
                if (up != null) {
                    event.preventDefault();
                    up.click();
                }
            }
            break;
        case 37: //left-arrow
        case 65: //a
            {
                if (left != null) {
                    event.preventDefault();
                    left.click();
                }
            }
            break;
        case 40: //down-arrow
        case 83: //s
            {
                if (down != null) {
                    event.preventDefault();
                    down.click();
                }
            }
            break;
        case 39: //right-arrow
        case 68: //d
            {
                if (right != null) {
                    event.preventDefault();
                    right.click();
                }
            }
            break;
        case 13: //enter
            {
                if (start != null) {
                    start.click();
                } else if (map != null) {
                    map.click();
                } else if (collect != null) {
                    collect.click();
                }
            }
            break;
	}
}));