GC - Lottomatic

Generate lotto numbers with minimal overlap

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         GC  - Lottomatic
// @version      0.1.1
// @description  Generate lotto numbers with minimal overlap
// @author       wibreth
// @namespace    neopets
// @match        https://www.grundos.cafe/games/lottery/*
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

// based on https://www.andrew.cmu.edu/user/kmliu/neopets/lottery.html 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>`);
        });
        $('#lotto-sprite-container').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() {
        $('.center form:last-child() .half-width').addClass('flex-column');
        var refreshbtn = $('<a>⭮</a>')
        refreshbtn.click(function() {
            refresh();
        });
        $('#lotto-sprite-container').append(refreshbtn);

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