// ==UserScript==
// @name           Expand URL on Yahoo Analytics
// @namespace      http://moto-mono.net/
// @include        https://report.analytics.yahoo.co.jp/servlet/*
// ==/UserScript==
//
// auther:  5509 http://moto-mono.net/
// version: 0.0.9 2009-08-07
//

new function(){

	// Set Styles
	// By Hashed CSS Styles
	function set_styles(elm,hash){
		for(var c in hash){
			elm.style[c] = hash[c];
		}
	}

	// Return URI
	// Return the original URI
	function return_URI(uri){
		var href;
		
		href = uri.replace(/http\:\/\/rd\.yahoo\.co\.jp\/analytics\/project\_list\/SIG=[\d\w]+\/\*/,'');
    	href = href.replace(/\%3A/,':');
    	
    	if(href.match(/\%/)){
    		var encoded = href.match(/\%[^\&\/]+/g);
    			
    		for(var j=0;j<encoded.length;j++){
    			href = href.replace(encoded[j],decodeURI(encoded[j]));
    		}
    	}
    	return href;
	}
	
	// ExpandURI
	function expandURI(){
	
		var exuoya_tip = document.createElement('div');
		
		set_styles(exuoya_tip,{
			marginRight: '5px',
			border: 'solid #006fff 1px',
			MozBorderRadius: '3px',
			padding: '3px 7px',
			position: 'absolute',
			display: 'none',
			color: '#fff',
			background: '#4D91F6',
			fontSize: '12px',
			opacity: .9
		});
		
		document.body.appendChild(exuoya_tip);
		
		var parent = document.getElementById('trcontent');
		var td = parent.getElementsByTagName('td');
		
		for(var i=0;i<td.length;i++){
			if(td[i].className.match(/custRepLine5/)){
				var a = td[i].getElementsByTagName('a')[0];
				if(a){
					var href = a.href, cut_off;
					
					href = return_URI(href);
					
					if(href.length>70){
						cut_off = href.slice(0,70)+'...';
						a.innerHTML = cut_off;
					}else{
						a.innerHTML = href;
					}
					
					
					a.addEventListener('mouseover',function(e){
						var _href = return_URI(this.href);
						
						set_styles(exuoya_tip,{
							top: e.pageY - 15,
							left: e.pageX + 15,
							display: 'block'
						});
						
						exuoya_tip.innerHTML = _href;
					},false);
					
					a.addEventListener('mouseout',function(){
						set_styles(exuoya_tip,{
							display: 'none'
						})
					},false);
					
					a.addEventListener('mousemove',function(e){
						set_styles(exuoya_tip,{
							top: e.pageY - 15,
							left: e.pageX + 15
						});
					},false)
				}
			}
		}
	}
	
	window.addEventListener('load',expandURI,false);
}
