KongreGet *OLD*

Gives stats while in chat

  1. // ==UserScript==
  2. // @name KongreGet *OLD*
  3. // @namespace KongregateGet
  4. // @description Gives stats while in chat
  5. // @include http://www.kongregate.com/games/*
  6. // @author Matthew Ammann
  7. // @version 1.4.3
  8. // @date 10/10/10
  9. // ==/UserScript==
  10. var dom = (typeof unsafeWindow === "undefined"?window:unsafeWindow);
  11.  
  12. function init_kongregateGet(dom){
  13. var holodeck = dom.holodeck;
  14. ChatDialogue = dom.ChatDialogue;
  15.  
  16. if(!holodeck) return;
  17. holodeck.addChatCommand("avglvl", function(l,n)
  18. {
  19. var roomDetails = l.chatWindow().activeRoom();
  20. var allUsers = roomDetails.users();
  21. var allLevels = 0;
  22. for(var i=0; i < allUsers.length; i++)
  23. {
  24. allLevels += allUsers[i].variables.level;
  25. }
  26. var avgLevel = Math.round(allLevels/allUsers.length*10)/10;
  27. l.activeDialogue().displayUnsanitizedMessage("Kong Bot", "Average Level in room: " + avgLevel , {"class":"whisper received_whisper"}, {non_user: true});
  28.  
  29. return false;
  30. })
  31.  
  32. if(holodeck && ChatDialogue && !holodeck._chat_commands.mostplayed)
  33. {
  34. //Credit goes entirely to Ventero for this command. Thanks for fixing the command after the Kongregate update, Vent :)
  35. holodeck.addChatCommand("mostplayed", function(l,n){
  36. var matchArr = n.match(/\/\S+\s+(\d+)/),
  37. dialog = l.activeDialogue(),
  38. gamesCount = 5,
  39. userList = dom.$A(l.chatWindow().activeRoom().users()),
  40. usersCount = userList.length;
  41. if(matchArr && matchArr[1]) gamesCount = matchArr[1];
  42. function p(count){
  43. return count == 1?"":"s";
  44. }
  45.  
  46. function makeLink(user){
  47. return '<a href="#" onclick="holodeck.showMiniProfile(\'' +
  48. user + '\'); return false;">' + user + '</a>';
  49. }
  50.  
  51. var games = dom.$H();
  52. userList.each(function(user){
  53. var o = user.variables.game_url;
  54. if(!games.get(o)){
  55. games.set(o, {
  56. title: user.variables.game_title,
  57. count: 0,
  58. user: "",
  59. url: o
  60. });
  61. }
  62. games.get(o).count++;
  63. games.get(o).user = user.username
  64. })
  65.  
  66. var countArr = games.values().sort(function(a,b){
  67. return +b.count - +a.count;
  68. }).slice(0, gamesCount);
  69. var totalCount = games.size();
  70.  
  71. dialog.unsanitizedKongBotMessage(usersCount + " user" + p(usersCount) + " playing " +
  72. totalCount + " different game" + p(totalCount));
  73.  
  74. dialog.unsanitizedKongBotMessage(gamesCount + " most played game" + p(gamesCount) + ":");
  75. countArr.each(function(obj){
  76. dialog.unsanitizedKongBotMessage(
  77. obj.count + " user" + p(obj.count) + " (" +
  78. (obj.count > 1 ? "" : makeLink(obj.user) + ", ") +
  79. (100*obj.count/usersCount).toFixed(1) + "%) " +
  80. (obj.count > 1 ? "are" : "is") + ' playing <a href="' +
  81. obj.url + '">' + obj.title + "</a>"
  82. );
  83. });
  84.  
  85. return false;
  86. });
  87. holodeck._chat_commands.mp = holodeck._chat_commands.mostplayed;
  88. holodeck._chat_commands.getmp = holodeck._chat_commands.mostplayed;
  89. (ChatDialogue.prototype||dom.CDprototype).unsanitizedKongBotMessage = function(message){
  90. this.displayUnsanitizedMessage("Kong Bot", message, {class: "whisper received_whisper"}, {non_user: true});
  91. }
  92. }
  93. }//end init()
  94.  
  95. function check(){
  96. var injectScript = dom.injectScript||(document.getElementById("injectScriptDiv")?document.getElementById("injectScriptDiv").onclick():0);
  97. if(injectScript){
  98. injectScript(init_kongregateGet, 0);
  99. } else if(!dom._promptedFramework && !/Chrome/i.test(navigator.appVersion)){
  100. if(confirm("You don't have the latest version of the framework-script!\n" +
  101. "Please install it, otherwise the scripts won't work.\n" +
  102. "Clicking ok will open a new tab where you can install the script"))
  103. window.open("http://userscripts.org/scripts/show/54245", "_blank");
  104. dom._promptedFramework = true;
  105. }
  106. }
  107.  
  108. setTimeout(check, 0);