Advertisement
KK20

Oldpage Bets Maker

Sep 18th, 2019
993
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Oldpage Bets Maker
  3. // @namespace    http://tampermonkey.net/
  4. // @version      1.0
  5. // @description  Allows user to generate a code to share with others that will place the same bets
  6. // @author       KK20
  7. // @match        http://neofoodclub.fr/oldpage.html*
  8. // @require      https://code.jquery.com/jquery-3.1.0.min.js
  9. // @grant        none
  10. // ==/UserScript==
  11.  
  12. this.$ = this.jQuery = jQuery.noConflict(true);
  13.  
  14. function place_bets() {
  15.     var bet_num, arena, pirate, substr_bet;
  16.  
  17.     var bet_code = $("input#bet_textarea").val();
  18.     if (bet_code.length % 5 != 0) {
  19.         alert("This is an invalid bet code! Please check that you copied it right.");
  20.         return;
  21.     }
  22.  
  23.     for(bet_num = 0; bet_num < bet_code.length / 5; bet_num++) {
  24.         substr_bet = bet_code.substring(bet_num * 5, bet_num * 5 + 5);
  25.         for(arena = 0; arena < 5; arena++) {
  26.             pirate = substr_bet[arena];
  27.             check_radio(arena, pirate, bet_num);
  28.         }
  29.     }
  30. }
  31.  
  32. function make_bet_code() {
  33.     var bets = Array(10).fill("");
  34.     $("input:radio").each(function(index, radio) {
  35.         if ($(this).is(":checked"))
  36.             bets[index % 10] += Math.floor(index % 50 / 10);
  37.     });
  38.     $("input#bet_textarea").val(bets.join(""));
  39. }
  40.  
  41. function check_radio(arena_id, pirate_row, bet_number) {
  42.     $("tbody:eq("+arena_id+") tr:eq("+pirate_row+") input:radio:eq("+(bet_number)+")").prop("checked", true).trigger("click");
  43. }
  44.  
  45. $("div#el a:first").after('<br><input id="bet_textarea" type="textbox"><input id="bet_submit" type="button" value="Place Bets!"><input id="gen_code" type="button" value="Generate Code">');
  46. $("input#bet_submit").on("click", place_bets);
  47. $("input#gen_code").on("click", make_bet_code);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement