Grumpy Wise King autofill

Auto selects the avatar question in Grumpy King

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

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

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

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

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

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Grumpy Wise King autofill
// @namespace    http://tampermonkey.net/
// @version      2021.01.30
// @description  Auto selects the avatar question in Grumpy King
// @match        *://www.neopets.com/medieval/wiseking.phtml
// @match        *://www.neopets.com/medieval/grumpyking.phtml
// ==/UserScript==

const $form = $("form[name='form']");

$form.before(`<p style="font-weight:bold; color:green; text-align:center;">Auto-filled by userscript!<br>Also hi, r/neopets discord :)</p>`).find("select").each(function (index, element) {
    const numOptions = $(element).find("option").length;
    const random = Math.floor(Math.random() * (numOptions - 1)) + 1;
    $(element).find("option").eq(random).prop("selected", true);
});

if (document.URL.includes("grumpyking")) {
    //["What", "do", "you do if", "*Leave blank*", "fierce", "Peophins", "*Leave blank*", "has eaten too much", "*Leave blank*", "tin of olives"];
    const avOptions = [3, 8, 6, 1, 39, 118, 1, 32, 1, 143];
    for (let i = 0; i < 10; i++) {
        $(`#qp${i + 1} option`).eq(avOptions[i]).prop("selected", true);
    }
}