GC Questing Keyboard Controls

Adds keyboard controls for questing on GC.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
    // @name         GC Questing Keyboard Controls
    // @namespace    http://tampermonkey.net/
    // @version      3.4.4
    // @description  Adds keyboard controls for questing on GC.
    // @author       Z & Dij
    // @match        https://www.grundos.cafe/halloween/esophagor/*
    // @match        https://www.grundos.cafe/island/kitchen/*
    // @match        https://www.grundos.cafe/winter/snowfaerie/*
    // @match        https://www.grundos.cafe/halloween/witchtower/*
    // @match        https://www.grundos.cafe/halloween/braintree/*
    // @match        https://www.grundos.cafe/winter/grundo/*
    // @match        https://www.grundos.cafe/safetydeposit/*
    // @match        https://www.grundos.cafe/market/wizard/*
    // @match        https://www.grundos.cafe/market/browseshop/?owner=*
    // @license      MIT
    // @icon https://www.google.com/s2/favicons?sz=64&domain=grundos.cafe
    // ==/UserScript==

    // shoutout to Dij for the massive optimization & to Berna and Kait for further JS help <3

    var rmOne = document.querySelector("a.sdb-remove-one-text");
    var search = document.querySelector("div.sw_search_submit input.form-control");
    var shop = document.querySelector(".market_grid.sw_results .data a:nth-child(1)");
    var myshop = document.querySelector("div.market_grid.sw_results.margin-1 div.data.sw_mine a");
    var buy = document.querySelector("#searchedItem.shop-item input[type='image']");
    var brain = document.querySelector("img[title='Brain Tree Quest']");
    var eso = document.querySelector("img[title='Esophagor Quest']");
    var chef = document.querySelector("img[title='Kitchen Quest']");
    var taelia = document.querySelector("img[title='Taelia Quest']");
    var edna = document.querySelector("img[title='Edna Quest']");

    document.addEventListener("keydown", (event) => {
        if ( !$('input:focus').length > 0 ) {
            if (event.keyCode == 13) { // keycode for enter
                if (rmOne != null) {
                    rmOne.click();
                } else if (buy != null) {
                    buy.click();
                } else if (search != null) {
                    search.click();
                } else if (myshop != null) {
                    myshop.click();
                } else if (shop != null) {
                    shop.click();
                } else if (location.pathname.match(/halloween|island|winter/)) {
                    let formbuttons = document.getElementById("page_content")
                      .querySelectorAll("form .form-control:not([type=text]), .form-control[type=button]");
                    if (formbuttons.length > 1) {
                        formbuttons[0].click();
                    } else {
                        window.location.reload();
                    }
                }
            }
        }
    });

document.addEventListener("keydown", (event) => {
    let codes = [37, 38, 39, 40] // keycodes for left, up, right, down arrows
    let index = codes.indexOf(event.keyCode);
    let itemlist = document.querySelectorAll(".shop-item");
    if (itemlist.length == 0 ) {
        itemlist = document.querySelectorAll(".shop-item,.quest-item,.centered-item");
    }
    if ( !$('input:focus').length > 0 ) {
        if (index >= 0 ) {
            let item =
                itemlist[index].querySelector(`img.search-helper-sdb-exists`);
            if (item != null) {
                item.click();
            } else {
                itemlist[index].querySelector(`img.search-helper-sw`).click();
            }
        }
    }
});

const actions = { // numbers 49-53 represent keycodes 1-5, change those to change the hot keys!
    49: () => edna.click(),   // 1
    50: () => eso.click(),    // 2
    51: () => taelia.click(), // 3
    52: () => chef.click(),   // 4
    53: () => brain.click()   // 5
};
document.addEventListener("keydown", (event) => {
    if ( !$('input:focus').length > 0 ) {
        if (actions[event.keyCode]) {
        actions[event.keyCode]();
        }
    }
});