Neopets - Lottomatic

Generate lotto numbers with minimal overlap

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Neopets - Lottomatic
// @version      0.1.2
// @description  Generate lotto numbers with minimal overlap
// @author       msjanny
// @namespace    neopets
// @match        https://www.neopets.com/games/lottery.phtml*
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

// originally https://www.andrew.cmu.edu/user/kmliu/neopets/lottery.html , used with permission

(function() {
    'use strict';
    /* globals $:false */

    var numbers = GM_getValue("numbers", "");

    function shuffle(o)
    {
        for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
        return o;
    };

    function leaf(a,b)
    {
        var res = new Array();
        for(var i=0; i<a.length; i++)
        {
            res[i*2] = a[i];
            res[i*2+1] = b[i];
        }
        return res;
    };

    function generate() {
        var arr = new Array();
        for(var i=0; i<30; i++)
            arr[i] = i+1;

        var arr1 = shuffle(arr);
        var arr2 = leaf( arr1.slice(0,15), arr1.slice(15,30) )
        var arr3 = leaf( arr2.slice(0,15), arr2.slice(15,30) )
        var arr4 = leaf( arr3.slice(0,15), arr3.slice(15,30) )
        var marr = arr1.concat(arr2,arr3,arr4);

        numbers = new Array();
        for(i=0; i<20; i++)
            numbers[i] = [marr[6*i], marr[6*i+1], marr[6*i+2], marr[6*i+3], marr[6*i+4], marr[6*i+5]];
        GM_setValue('numbers', numbers);
        populate();
    };

    function refresh() {
        $('.tickets').remove();
        numbers = [];
        generate();
    };

    function populate() {
        var radiodiv = $('<div class="tickets" style="font-size: 0.8em">');
        numbers.forEach((ticket, idx) => {
            radiodiv.append(`<div><input type="radio" id="${idx+1}" name="ticket" value="${idx}">
            <label for="${idx+1}">${idx+1}: ${ticket.join(', ')}</label></div>`);
        });
        $('td[width=160]').append(radiodiv);
        $('.tickets input').change(function() {
            var ticket = numbers[$(this).val()];
            $('input[name="one"]').val(ticket[0]);
            $('input[name="two"]').val(ticket[1]);
            $('input[name="three"]').val(ticket[2]);
            $('input[name="four"]').val(ticket[3]);
            $('input[name="five"]').val(ticket[4]);
            $('input[name="six"]').val(ticket[5]);
        });
        $('label').click(function() {
            let id = $(this).prop("for");
            $("#" + id).click();
        });
    }

    $('document').ready( function() {
        var refreshbtn = $('<a>⭮</a>')
        refreshbtn.click(function() {
            refresh();
        });
        $('td[width=160]').append(refreshbtn);

        if (!numbers)
            generate();
        else
            populate();
    });
})();