Lottery Ticket Generator

Generates 6 random numbers

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Lottery Ticket Generator
// @namespace    neopets
// @version      2020.01.18.2
// @description  Generates 6 random numbers
// @match        http://www.neopets.com/games/lottery.phtml
// @require      https://code.jquery.com/jquery-3.5.1.min.js
// ==/UserScript==

$("form[action='process_lottery.phtml'] table").css({"width" : "auto"}).find("tbody tr").append(`&nbsp;<td style="padding:10px;"><button id="randomTicket" type="button">Random</button></td>`);

const genNum = (min, max) => Math.floor(Math.random() * max) + min;

const genTicket = () => {
    let ticket = [];
    for (let i = 0; i < 6; i++) {
        let randomNumber = genNum(1, 30);
        while (ticket.includes(randomNumber)) {
            randomNumber = genNum(1, 30);
        }
        ticket.push(randomNumber);
    }
    ticket.sort((a, b) => a - b);
    return ticket;
};

$("#randomTicket").on("click", function (event) {
    event.preventDefault();
    const ticket = genTicket();
    $("form[action='process_lottery.phtml'] table input").each(function (index, element) {
        $(element).val(ticket[index]);
    });
}).click();