Neopets - Lottomatic

Generate lotto numbers with minimal overlap

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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