Neopets Random Lottery Links

Button to generate 20 random lottery ticket links on neopets

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

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

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.

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

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         Neopets Random Lottery Links
// @namespace    shiftasterisk
// @version      0.1
// @description  Button to generate 20 random lottery ticket links on neopets
// @author       shiftasterisk
// @match        http://www.neopets.com/games/lottery.phtml
// @include      https://code.jquery.com/jquery-3.1.1.min.js
// @grant        none
// ==/UserScript==

$('input[type="submit"][value="Buy a Lottery Ticket!"]').parent().append("<input id='buyTwenty' type='button' value='Generate Quick Picks'>");
$('input[type="submit"][value="Buy a Lottery Ticket!"]').parent().parent().parent().append("<div id='linkContainer'></div>");

var numberOfTickets = 20;
var tickets = [];

$('#buyTwenty').click(function() {
	tickets = [];
	$("#linkContainer").empty();
	selectTickets();
	displayTicketLinks();
});

function displayTicketLinks() {
	for(x = 0; x < tickets.length; x++) {
		$("#linkContainer").append('<a target="_blank" href="http://www.neopets.com/games/process_lottery.phtml?one=' + tickets[x][0] + '&two=' + tickets[x][1] + '&three=' + tickets[x][2] + '&four=' + tickets[x][3] + '&five=' + tickets[x][4] + '&six=' + tickets[x][5] + '">Ticket ' + (x+1) + '</a><br>');
	}
}

function selectTickets() {
	var ticketsAdded = 0;
	while(ticketsAdded < numberOfTickets) {
		currentTicket = [];
		for(y = 0; y < 6; y++) {
			currentTicket = addNumberToTicket(currentTicket);
		}
		if(!isDuplicateTicket(currentTicket)) {
			tickets.push(currentTicket);
			ticketsAdded++;
            console.log("totalTickets - " + ticketsAdded);
		} else {
            currentTicket = [];
        }
	}
}

function addNumberToTicket(currentTicket){
	var lotteryNumber = Math.round(Math.random() * 29) + 1;
	console.log(currentTicket);
    console.log(lotteryNumber);
    
	if(currentTicket.includes(lotteryNumber)) {
        console.log("duplicate number - going in again");
		currentTicket = addNumberToTicket(currentTicket);
    } else {
		currentTicket.push(lotteryNumber);
    }
	
	return currentTicket;
}

function isDuplicateTicket(currentTicket) {
	for(x = 0; x < tickets.length; x++) {
		if(JSON.stringify(currentTicket.sort()) === JSON.stringify(tickets[x].sort())) {
            console.log("duplicate ticket");
			return true;
        }
	}
	return false;
}