General Badges *OLD*

Changes the General Badges page, with Ajax loading of Badges

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name           General Badges *OLD*
// @description	   Changes the General Badges page, with Ajax loading of Badges
// @version        1.0
// @include        http://www.kongregate.com/badges
// @include	   http://kongregate.com/badges
// @namespace https://greatest.deepsurf.us/users/32649
// ==/UserScript==

(function(){
	window.addEventListener('load', function(event){
		// Get Ajax Object From Prototype
		Ajax = unsafeWindow['Ajax'];
		Effect = unsafeWindow['Effect'];
		Element = unsafeWindow['Element'];
		initButtons();
		
		var d = document.createElement('div');
		d.id='loadingdiv';
		d.innerHTML = 'loading...';
		var f = document.getElementById('feature');
		f.insertBefore(d,f.firstChild);
		Element.setStyle('loadingdiv', {
			background:'url(http://chat.kongregate.com/images/presentation/indicator.gif) top right no-repeat',
			height:'20px',
			width:'80px',
			opacity:'0',
			display:'none',
			fontSize:'1.1em',
			float:'left'
		});
		
	}, 'false');
})();
function initButtons(){
	// Get Those Link Buttons
	var b = new Array;
	
	for (var i = 0; i<2; i++){
		var p = document.getElementById('main').getElementsByTagName('ul')[i].getElementsByTagName('a');
		for(var o = 0; o < p.length; o++){
			b.push(p[o]);
		}
	}
	for (var i = 0; i < b.length; i++){
		b[i].addEventListener('click', function(e){
			e.preventDefault();
			
			new Ajax.Request(this.href,{
				method: 'get',
				onCreate: function(){
					new Effect.Opacity('main',{
						duration:.2,
						from:1.0,
						to:0,
						afterFinish: function(){
							new Effect.Opacity('loadingdiv',{
								duration:.2,
								from:0,
								to:1.0,
								beforeStart: function(){
									Element.setStyle('loadingdiv', {
										display:'block'
									});
									Element.setStyle('main',{
										display:'none'
									});
								}
							});
						}
					});
				},
				onSuccess: function(transport){
					new Effect.Opacity('main',{
						duration:.4,
						from:0,
						to:1.0,
						beforeStart: function(){
							new Effect.Opacity('loadingdiv',{
								duration:.2,
								from:1.0,
								to:0,
								beforeStart: function(){
								
									var x = (new DOMParser()).parseFromString(transport.responseText,"text/xml");
									var d = x.getElementsByTagName('div');
									
									document.getElementById('main').innerHTML = extractMain(d,'main');
									document.getElementById('sidebar').innerHTML = extractMain(d,'sidebar');
									initButtons();
									
									Element.setStyle('loadingdiv', {
										display:'none'
									});
									Element.setStyle('main',{
										display:'block'
									});
								}
							});
						}
					});
				}
			});
			return(false);
		},false);
	}
}
function extractMain(d,id){
	for (var i = 0; i<d.length; i++){
		if (d[i].id == id){
			return d[i].innerHTML;
		}
	}
	return 'nothing';
}