General Badges *OLD*

Changes the General Badges page, with Ajax loading of Badges

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(У мене вже є менеджер скриптів, дайте мені встановити його!)

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.

(I already have a user style manager, let me install it!)

// ==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';
}