More UI part2

The second part to The GT UI+

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name       More UI part2
// @namespace  http://use.i.E.your.homepage/
// @version    1.0.2.1
// @description The second part to The GT UI+
// @match      http://www.ghost-trappers.com/fb/camp.php*
// @match      http://www.ghost-trappers.com/fb/hunt.php*
// @copyright  2015+, GTNoAPI
// @grant      GM_xmlhttpRequest
// ==/UserScript==

initUIv2();

function initUIv2(){
	GM_xmlhttpRequest({
			method: 'GET',
			url: 'https://gtnoapi.herokuapp.com/api/ghosts',
			headers: {
				"Accept": "application/json",
				"Pragma": "no-cache",
				"Cache-Control": "no-cache"
			},
			onload: function(rD) {
				$('.logText').each(function(){
					var ghostEncounter = $(this).find('a').html();
					var ghostInfo = getGhostByName(ghostEncounter, rD.response);
					if(ghostEncounter && ghostEncounter == ghostInfo.name){
						var perantEle;
						var childEle;
						if(ghostInfo.loot){

							var arrow= $('<div></div>').css({
								'width': '0' ,
								'height': '0',
								'border-top': '10px solid transparent',
								'border-bottom': '10px solid transparent',
								'border-left': '10px solid #223341',
								'position': 'absolute',
								'top': '10px',
								'right': '-10px',
							})

							childEle = $('<span></span>').css({
								'position': 'absolute',
								'top': '-14px',
								'right': '40px',
								'z-index': '9999999',
								'font-size': '14px',
								'display': 'none',
								'background-color': '#223341',
								'border': '1px solid #222',
								'border-radius': '7px',
								'padding': '10px',
								'min-width': '150px'

							}).html(ghostInfo.loot);


							 perantEle = $('<div>?</div>').css({
								 'cursor':'pointer',
								 'padding': '1px 4.5px',
								 'border-radius': '50%',
								 'background-color': 'black',
								 'color': 'white',
								 'float': 'right',
								 'font-weight': 'bold',
								 'position': 'relative'
							 });


							perantEle.hover(function(){
								if(childEle.css('display')=='none'){
									childEle.show();
								}
								else{
									childEle.hide();
								}
							});

							arrow.appendTo(childEle);
							childEle.appendTo(perantEle)
						}




						$(this).append(perantEle);
					}
				});
			}
		});
};


function getGhostByName(name, jsonTxt){
	
	var obj = jQuery.parseJSON(jsonTxt);
	var result = '';
	for(var x = 0; x < obj.length; x++){
		if(obj[x].name == name){
			var title = '';
			for(var y = 0; y < obj[x].loot.length; y++){
				title += obj[x].loot[y] + '<br />';
			}
			
			result = {
				'name':obj[x].name,
				'loot':title,
				'type':obj[x].type
			}
			
		}
		
	}
	
	
	return result;
}