Sixtest Wiki:API/Code

function clearInterface(i) { var changed; if (i === undefined) { i = TWAPI.Interface; }   do { changed = 0; for (e in i) { if (i[e].children.length === 0) { i[e].parentNode.removeChild(i[e]); delete(i[e]); changed += 1; }       }    } while (changed !== 0); } function inArray(needle, haystack) { var i = 0, len = haystack.length; for(i; i<len; i += 1) { if (haystack[i] === needle) { return true; }	}	return false; } function addInterfaceElement(e, n, p, s, c) { if (TWAPI.Interface[n] === undefined) { p = TWAPI.Interface[p]; if (p !== undefined) { var o = document.createElement(e); if (s !== undefined) { for (css_i in s) { o.style[css_i] = s[css_i]; }			}			if (c !== undefined) { for (js_i in c) { o[js_i] = c[js_i]; }			}			TWAPI.Interface[n] = o;			p.appendChild(TWAPI.Interface[n]); return TWAPI.Interface[n]; }	}	return false; } function TWAPI_Init { window.TWAPI = { baseURL: 'http://sixtest.wikia.com/wiki/Sixtest_Wiki:API/', scripts: { installed: [], all: [], },		Interface: { Container: document.getElementById('API-Interface') },		extInit: function (ext, cnf) { /* initialize extension */ if (ext.name === undefined || ext.name === '') { alert('Error: unnamed extension.'); return false; } else { TWAPI.scripts.installed[TWAPI.scripts.installed.length] = ext.name; }			cnf = true; // how to work around bad code ? (asking for confirmation to install doesn't work if they can run self-executing functions) if (cnf === undefined) { cnf = confirm('Do you really want to enable the ' + ext.name + ' script?'); }			if (cnf === true) { ext.init; return true; } else { return false; }		},		loadScript: function (ext) { $.ajax( {				url: 'http://sixtest.wikia.com/wiki/Sixtest_Wiki:API/' + ext + '?action=raw',				dataType: 'text',				async: false,				success: function(text) {					var e = document.createElement('script');					e.setAttribute('type', 'text/javascript');					e.text = text;					var at = document.getElementsByTagName('head')[0];					at.appendChild(e);				}			} ); },	};	(function {		var tmp = $.ajax( { url: 'http://sixtest.wikia.com/wiki/Sixtest_Wiki:API/Scripts?action=raw', async: false, dataType: 'text', success: function(text) { var e = document.createElement('script'); e.setAttribute('type', 'text/javascript'); e.text = text; var at = document.getElementsByTagName('head')[0]; at.appendChild(e); }		} )	});

} TWAPI_Init; TWAPI.loadScript('Scripts'); TWAPI.loadScript('Item'); TWAPI.loadScript('SearchSuggest');