NecromancerCoding

Randomización de llamadas de usuario

Jun 23rd, 2022 (edited)
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.93 KB | None | 0 0
  1. $(document).ready(function(){
  2. $('.usersrandom').each(function(){
  3. var users = ["/u2", "/u3", "/u4", "/u5", "/u6", "/u7", "/u8"];
  4. var size = users.length;
  5. var a = Math.floor(size*Math.random());
  6. var b = Math.floor(size*Math.random());
  7. var c = Math.floor(size*Math.random());
  8. var d = Math.floor(size*Math.random());
  9. var e = Math.floor(size*Math.random());
  10. var $self = $(this);
  11. /* Tendrías que repetir esto tantas veces como variables de randomización tengas */
  12. $.get(users[a], function(data) {
  13. var randomAvatar = $(data).find('.psavatar').html();
  14. var randomUsername = $(data).find('.psname').html();
  15. $self.append('<div class="userrandom userrandom-a"><div class="ur-avatar">'+randomAvatar+'</div><div class="ur-name">'+randomUsername+'</div></div>');
  16. });
  17. $.get(users[b], function(data) {
  18. var randomAvatar = $(data).find('.psavatar').html();
  19. var randomUsername = $(data).find('.psname').html();
  20. $self.append('<div class="userrandom userrandom-b"><div class="ur-avatar">'+randomAvatar+'</div><div class="ur-name">'+randomUsername+'</div></div>');
  21. });
  22. $.get(users[c], function(data) {
  23. var randomAvatar = $(data).find('.psavatar').html();
  24. var randomUsername = $(data).find('.psname').html();
  25. $self.append('<div class="userrandom userrandom-c"><div class="ur-avatar">'+randomAvatar+'</div><div class="ur-name">'+randomUsername+'</div></div>');
  26. });
  27. $.get(users[d], function(data) {
  28. var randomAvatar = $(data).find('.psavatar').html();
  29. var randomUsername = $(data).find('.psname').html();
  30. $self.append('<div class="userrandom userrandom-d"><div class="ur-avatar">'+randomAvatar+'</div><div class="ur-name">'+randomUsername+'</div></div>');
  31. });
  32. $.get(users[e], function(data) {
  33. var randomAvatar = $(data).find('.psavatar').html();
  34. var randomUsername = $(data).find('.psname').html();
  35. $self.append('<div class="userrandom userrandom-e"><div class="ur-avatar">'+randomAvatar+'</div><div class="ur-name">'+randomUsername+'</div></div>');
  36. });
  37. });
  38. });
Add Comment
Please, Sign In to add comment