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.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==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;
        }
    });
})();