Advertisement
Guest User

Tournament Participants JSON

a guest
Apr 8th, 2019
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function participantsToJSON(){
  2.     var participants = [];
  3.    
  4.     $(".playerList tr").each(function(index, value){
  5.        
  6.         if(index == 0){
  7.             return;
  8.         }
  9.        
  10.         console.log(index);
  11.        
  12.         var trainerName = $(this).find(".registrantListEntry").html();
  13.        
  14.         // Remove extra characters
  15.        
  16.         trainerName = trainerName.replace('\n                      ','');
  17.         trainerName = trainerName.replace('                                          ','');
  18.        
  19.         var pokemon = [];
  20.        
  21.         $(this).find(".pokemonEntry").each(function(index, value){
  22.             pokemon.push({ name: $(this).find("p").last().html(), cp: $(this).find(".cp").html() });
  23.         });
  24.        
  25.         participants.push({ trainer: trainerName, pokemon: pokemon});
  26.     });
  27.    
  28.     var json = JSON.stringify(participants);
  29.    
  30.     console.log(json);
  31.    
  32.     return json;
  33. }
  34.  
  35. participantsToJSON();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement