// ==UserScript== // @name Oldpage Bets Maker // @namespace http://tampermonkey.net/ // @version 1.0 // @description Allows user to generate a code to share with others that will place the same bets // @author KK20 // @match http://neofoodclub.fr/oldpage.html* // @require https://code.jquery.com/jquery-3.1.0.min.js // @grant none // ==/UserScript== this.$ = this.jQuery = jQuery.noConflict(true); function place_bets() { var bet_num, arena, pirate, substr_bet; var bet_code = $("input#bet_textarea").val(); if (bet_code.length % 5 != 0) { alert("This is an invalid bet code! Please check that you copied it right."); return; } for(bet_num = 0; bet_num < bet_code.length / 5; bet_num++) { substr_bet = bet_code.substring(bet_num * 5, bet_num * 5 + 5); for(arena = 0; arena < 5; arena++) { pirate = substr_bet[arena]; check_radio(arena, pirate, bet_num); } } } function make_bet_code() { var bets = Array(10).fill(""); $("input:radio").each(function(index, radio) { if ($(this).is(":checked")) bets[index % 10] += Math.floor(index % 50 / 10); }); $("input#bet_textarea").val(bets.join("")); } function check_radio(arena_id, pirate_row, bet_number) { $("tbody:eq("+arena_id+") tr:eq("+pirate_row+") input:radio:eq("+(bet_number)+")").prop("checked", true).trigger("click"); } $("div#el a:first").after('
'); $("input#bet_submit").on("click", place_bets); $("input#gen_code").on("click", make_bet_code);