Average level

Returns the average level of the current chat room

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name           Average level
// @namespace      arreloco
// @description    Returns the average level of the current chat room
// @include        http://www.kongregate.com/games/*
// @version 0.0.1.20160306133113
// ==/UserScript==
function init()
{
	var dom;

	try{
		if(unsafeWindow){
			dom = unsafeWindow;
		} else {
			dom = this;
		}
	}catch(e){
		dom = this;
	}

	var holodeck = dom.holodeck;
	
		//Credit goes partially to Ventero for this command
		holodeck.addChatCommand("average", function(l,n){
			var matchArr = n.match(/^\/\S+\s+(\d+)/),
					userList = l.chatWindow().activeRoom().users(),
					countArr = [];
					
			var total_level = 0;
			var max_level = 0;
			var best_user = "";
			var plus_40_users = [];

			for(var i=0;i<userList.length;i++){
				total_level += userList[i].variables.level;
				if(userList[i].variables.level>max_level){
					best_user = userList[i].variables.username;
					max_level = userList[i].variables.level;
				}
				if(userList[i].variables.level>39){
					plus_40_users.push("\n <a href=\"http://www.kongregate.com/accounts/"+userList[i].variables.username+"\" target=\"_blank\">"+userList[i].variables.username+"</a>");
				}
			}
			
			var average_level = Math.round(total_level/userList.length*10)/10;
			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});
			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});
			
			return false;
		})
		
		holodeck._chat_commands.media = holodeck._chat_commands.average;
}//end init()

setTimeout(init,0);