Average level

Returns the average level of the current chat room

  1. // ==UserScript==
  2. // @name Average level
  3. // @namespace arreloco
  4. // @description Returns the average level of the current chat room
  5. // @include http://www.kongregate.com/games/*
  6. // @version 0.0.1.20160306133113
  7. // ==/UserScript==
  8. function init()
  9. {
  10. var dom;
  11.  
  12. try{
  13. if(unsafeWindow){
  14. dom = unsafeWindow;
  15. } else {
  16. dom = this;
  17. }
  18. }catch(e){
  19. dom = this;
  20. }
  21.  
  22. var holodeck = dom.holodeck;
  23. //Credit goes partially to Ventero for this command
  24. holodeck.addChatCommand("average", function(l,n){
  25. var matchArr = n.match(/^\/\S+\s+(\d+)/),
  26. userList = l.chatWindow().activeRoom().users(),
  27. countArr = [];
  28. var total_level = 0;
  29. var max_level = 0;
  30. var best_user = "";
  31. var plus_40_users = [];
  32.  
  33. for(var i=0;i<userList.length;i++){
  34. total_level += userList[i].variables.level;
  35. if(userList[i].variables.level>max_level){
  36. best_user = userList[i].variables.username;
  37. max_level = userList[i].variables.level;
  38. }
  39. if(userList[i].variables.level>39){
  40. plus_40_users.push("\n <a href=\"http://www.kongregate.com/accounts/"+userList[i].variables.username+"\" target=\"_blank\">"+userList[i].variables.username+"</a>");
  41. }
  42. }
  43. var average_level = Math.round(total_level/userList.length*10)/10;
  44. l.activeDialogue().displayUnsanitizedMessage("Kong Bot", "The average level of this room is "+average_level+" and the best user is <a href=\"http://www.kongregate.com/accounts/"+best_user+"/\" target=\"_blank\">"+best_user+"</a> (lvl "+max_level+").", {"class":"whisper received_whisper"}, {non_user: true});
  45. l.activeDialogue().displayUnsanitizedMessage("Kong Bot", "Here are all the users who are > or equal to 40:"+plus_40_users, {"class":"whisper received_whisper"}, {non_user: true});
  46. return false;
  47. })
  48. holodeck._chat_commands.media = holodeck._chat_commands.average;
  49. }//end init()
  50.  
  51. setTimeout(init,0);