<commit_before>/* XHR based image loader */
var xhrImages = {

cache:		{ },
loading:	{ },

/*
	Load an image with XHR, if required.

	By default this function will attempt to return the original URL if it
	appears to be valid.

	This is needed for some use cases, such as chrome packaged apps which are
	not permitted to reference an image URL that does not match the app's origin
*/
load: function(url, cb, force) {
	var chromeapp	= false;

	try {
		if (chrome.app.window) {
			chromeapp = true;
		}
	} catch(e) {
	}

	if (!chromeapp && !force) {
		/* On most platforms the existing URL is just fine */
		cb(url, true);
		return;
	}

	if (0 == url.indexOf("blob:")) {
		/* This URL has already been converted to a blob */
		cb(url, true);
		return;
	}

	if (typeof(xhrImages.cache[url]) !== "undefined") {
		/* We have a cached blob */
		cb(xhrImages.cache, true);
		return;
	}

	if (xhrImages.loading[url]) {
		/* The image has already been requested */
		xhrImages.loading[url].push(cb);
		return;
	}

	xhrImages.loading[url] = [ cb ];

	var xhr	= new XMLHttpRequest();

	xhr.open('GET', url, true);
	xhr.responseType = 'blob';

	xhr.onload = function(e) {
		if (typeof(xhrImages.cache[url]) !== "undefined") {
			console.log('Double loaded image:', url);<commit_msg>Cleaned up the xhr image loader needed when running as a chrome app, and implemented a cache<commit_after>/* XHR based image loader */
var xhrImages = {

cache:		{ },
loading:	{ },

/*
	Load an image with XHR, if required.

	By default this function will attempt to return the original URL if it
	appears to be valid.

	This is needed for some use cases, such as chrome packaged apps which are
	not permitted to reference an image URL that does not match the app's origin
*/
load: function(url, cb, force)
{
	var chromeapp	= false;

	try {
		if (chrome.app.window) {
			chromeapp = true;
		}
	} catch(e) {
	}

	if (!chromeapp && !force) {
		/* On most platforms the existing URL is just fine */
		cb(url, true);
		return;
	}

	if (0 == url.indexOf("blob:")) {
		/* This URL has already been converted to a blob */
		cb(url, true);
		return;
	}

	if (typeof(xhrImages.cache[url]) !== "undefined") {
		/* We have a cached blob */
		cb(xhrImages.cache[url], true);
		return;
	}

	if (xhrImages.loading[url]) {
		/* The image has already been requested */
		xhrImages.loading[url].push(cb);
		return;
	}

	xhrImages.loading[url] = [ cb ];

	var xhr	= new XMLHttpRequest();

	xhr.open('GET', url, true);
	xhr.responseType = 'blob';

	xhr.onload = function(e) {
		if (typeof(xhrImages.cache[url]) !== "undefined") {
			console.log('Double loaded image:', url);
{'fraction_non_alphanumeric': 0.13757621951219512, 'fraction_numerical': 0.0007621951219512195, 'mean_word_length': 3.3969849246231156, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6676226', 'n_tokens_mistral': 960, 'n_tokens_neox': 890, 'n_words': 305}