GC Keyboard Shop Browser

Allows ArrowKey, WASD, and NumPad shop browsing. The first shop item will automatically be focused, then the arrow keys, WASD, or 8426 (for NumPads) will navigate between items.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         GC Keyboard Shop Browser
// @namespace    https://www.grundos.cafe/userlookup/?user=hazr
// @version      1.0
// @description  Allows ArrowKey, WASD, and NumPad shop browsing. The first shop item will automatically be focused, then the arrow keys, WASD, or 8426 (for NumPads) will navigate between items.
// @author       hazr
// @license      MIT
// @match        https://www.grundos.cafe/viewshop/*
// @match        https://www.grundos.cafe/market/browseshop/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=grundos.cafe
// @grant        none
// @run-at       document-start
// ==/UserScript==

var items = [];
var selectedItem = 0;
var maxIndex = 0;
var loaded = false;

new MutationObserver(function(mutations)
                     {
    items = document.querySelectorAll('#searchedItem form > input[type="image"], #shopInventory form > input[type="image"]');
    if (items)
    {
        items[0].focus();
        selectedItem = 0;
        maxIndex = items.length - 1;
        loaded = true;

        this.disconnect();
    }
}).observe(document, {childList: true, subtree: true});

(function() {
    'use strict';

    // Listen for keydown events
    document.addEventListener('keydown', function(event) {
        if (!loaded || maxIndex < 0 || document.activeElement.attributes.getNamedItem("type")?.value == "text") return;
        switch(event.key) {
            case "ArrowLeft":
            case "a":
            case "4":
                if ((selectedItem -= 1) < 0) selectedItem = 0;
                items[selectedItem].focus();
                break;
            case "ArrowRight":
            case "d":
            case "6":
                if ((selectedItem += 1) > maxIndex) selectedItem = maxIndex;
                items[selectedItem].focus();
                break;
            case "ArrowUp":
            case "w":
            case "8":
                if ((selectedItem -= 4) < 0) selectedItem = 0;
                items[selectedItem].focus();
                break;
            case "ArrowDown":
            case "s":
            case "2":
                if ((selectedItem += 4) > maxIndex) selectedItem = maxIndex;
                items[selectedItem].focus();
                break;
        }
    });
})();