<commit_before>var downloads =
{
	// url - string
	// passFunction - function (string url, string text)
	// failFunction - function (string url, int status)
	add: function (url, passFunction, failFunction)
	{
		var download = {}
		download.url = url;
		download.passFunction = passFunction;
		download.failFunction = failFunction;
		this._queue.push(download);
		this._update();
	},

	// Internal

	_active: [],
	_queue: [],
	_maxActive: 10,
	_update: function()
	{
		if(this._active.length < this._maxActive && this._queue.length > 0)
		{
			var download = this._queue.shift();
			var request = new XMLHttpRequest();
			request.onreadystatechange = function ()
			{
				if(request.readyState == 4)
				{
					if(request.status == 200 || request.status == 0)
					{
						if(download.passFunction)
						{
							download.passFunction(download.url, request.responseText);
						}
					}
					else
					{
						if(download.failFunction)
						{
							download.failFunction(download.url, request.status);
						}
					}
					downloads._update();
				}
			}
			request.open("GET", download.url, true);
			request.send();
		}
	}
}<commit_msg>Made downloads be able to dynamically load scripts<commit_after>var downloads =
{
	// url - string
	// pass - function (string url, string text)
	// fail - function (string url, int status)
	add: function(url, pass, fail)
	{
		var download = new this._Download(url, pass, fail, false);
		this._queue.push(download);
		this._update();
	},
	
	// url - string
	// pass - function (string url)
	// fail - function (string url)
	addScript: function(url, load, fail)
	{
		var download = new this._Download(url, load, fail, true);
		this._queue.push(download);
		this._update();
	},

	// Internal

	_Download: function(url, pass, fail, script)
	{
		this.url = url;
		this.pass = pass;
		this.fail = fail;
		this.script = script;
	},

	_active: [],
	_queue: [],
	_maxActive: 10,

	_update: function()
	{
		if(this._active.length < this._maxActive && this._queue.length > 0)
		{
			var download = this._queue.shift();
			if(download.script)
			{
				var script = document.createElement('script');
				script.src = download.url;
				if(download.pass)
				{
					script.onload = download.pass.bind(undefined, download.url);
				}
				if(download.fail)
				{
					script.onerror = download.fail.bind(undefined, download.url);
				}
				document.getElementsByTagName('head')[0].appendChild(script);
			}
			else
			{
				var request = new XMLHttpRequest();
				request.onreadystatechange = function()
				{
					if(request.readyState == 4)
					{
						if(request.status == 200 || request.status == 0)
						{
							if(download.pass)
							{
								download.pass(download.url, request.responseText);
							}
						}
						else
						{
							if(download.fail)
							{
								download.fail(download.url, request.request.status);
							}
						}
						downloads._update();
					}
				}
				request.open("GET", download.url, true);
				request.send();
			}
		}
	}
}
{'fraction_non_alphanumeric': 0.14323873121869782, 'fraction_numerical': 0.005676126878130217, 'mean_word_length': 2.605294825511432, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 41, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5341952', 'n_tokens_mistral': 1275, 'n_tokens_neox': 963, 'n_words': 195}