<commit_before>(function() {
	var messageID = 0, messageCallbacks = {};
	var action = function(action, args, callback, progress) {
		parent.postMessage({messageID: ++messageID, action: action, args: args}, '*');
		messageCallbacks[messageID] = callback;
		if(messageCallbacks[messageID]) messageCallbacks[messageID].progress = progress;
	};
	window.addEventListener('message', function(message) {
		if(message.source === parent) {
			if(message.data.inReplyTo) {
				var callback = messageCallbacks[message.data.inReplyTo];
				if(message.data.progress) callback = callback.progress;
				callback.apply(window, message.data.result);
				if(!message.data.progress) messageCallbacks[message.data.inReplyTo] = null;
			} else if(message.data.action) {
				airborn.listeners[message.data.action + 'Request'].forEach(function(listener) {
					listener.apply(airborn, message.data.args);
				});
			}
		} else if([].map.call(document.getElementsByTagName('iframe'), function(iframe) { return iframe.contentWindow; }).indexOf(message.source) !== -1) {
			action(message.data.action, message.data.args, function() {
				message.source.postMessage({inReplyTo: message.data.messageID, result: [].slice.call(arguments)}, '*');
			}, function() {
				message.source.postMessage({inReplyTo: message.data.messageID, result: [].slice.call(arguments), progress: true}, '*');
			});
		} else if(message.source === top) {
			console.log(document.getElementsByTagName('iframe').length);
		} else {
			console.info('unknown source');
		}
	}, false);
	airborn = laskya = {
		listeners: {
			openFileRequest: []
		},
		addEventListener: function(eventName, listener) {
			airborn.listeners[eventName].push(listener);
		}
	};
	function addAction(name) {
		var parts = name.split('.');
		var target = airborn;
		parts.slice(0, -1).forEach(function(part) {
			if(!target[part]) target[part] = {};
			target = target[part];
		});
		target[parts[parts.length - 1]] = function() {
			var args = [].slice.call(arguments);
			var firstfunction = args.map(function(arg) { return Object.prototype.toString.call(arg); }).indexOf('[object Function]');
			if(firstfunction === -1) firstfunction = args.length;
			action(name, args.slice(0, firstfunction), args[firstfunction], args[firstfunction + 1]);
		};
	}
	addAction('wm.focus');
	addAction('wm.setTitle');
	addAction('wm.setIcon');
	addAction('wm.openFile');
	addAction('wm.openWindow');
	addAction('wm.showProgress');
	addAction('wm.setProgress');
	addAction('wm.hideProgress');

	addAction('fs.getFile');
	addAction('fs.putFile');
	addAction('fs.prepareFile');
	addAction('fs.prepareString');
	addAction('fs.prepareUrl');
	addAction('fs.startTransaction');
	addAction('fs.endTransaction');
	
	navigator.mozApps = {};
	navigator.mozApps.installPackage = function() {
		var args = [].slice.call(arguments);
		var request = new DOMRequest();
		action('apps.installPackage', args, function(result, err) {
			if(err) {
				request.error = err;
				if(request.onerror) request.onerror();
			} else {
				request.result = result;
				if(request.onsuccess) request.onsuccess();
			}
		});
		return request;
	};

	var title = document.getElementsByTagName('title')[0];
	if(title) airborn.wm.setTitle(title.textContent);
	var icon = document.querySelector('link[rel="shortcut icon"], link[rel="icon"]');
	if(icon) airborn.wm.setIcon(icon.href);
	window.addEventListener('focus', function() {
		airborn.wm.focus();
	}, true);

	var requestOpen = XMLHttpRequest.prototype.open;
	var rSchema = /^[a-z]+:/i;
	var rArgs = /[?#].*$/;
	var root;
	(function() {
		var href = location.href;
		var sourceURLIndex = href.lastIndexOf('sourceURL%3D') + 12;
		var commentEndIndex = href.indexOf('%20--%3E', sourceURLIndex);
		root = decodeURIComponent(href.substring(sourceURLIndex, commentEndIndex) + href.substr(commentEndIndex + 8));
	})();
	XMLHttpRequest.prototype.open = function(method, url) {
		if(url.substr(0, 7) === 'data://' && url.indexOf(',') === -1) url = 'editor/' + url.substr(7); // Workaround for URI.js in Firetext
		if(method === 'GET' && !rSchema.test(url)) {
			this.airbornFile = true;
			this.setRequestHeader = function() { console.log(this, arguments); };
			var codec;
			this.overrideMimeType = function(mimeType) {
				console.log(this, arguments);
				// mimeType is of the form mime/type; charset=utf-8
				if(mimeType.split('/')[0] === 'text') return;
				console.log("codec = 'arrayBuffer';");
				codec = 'arrayBuffer';
			};<commit_msg>Move part of workaround to Firetext<commit_after>(function() {
	var messageID = 0, messageCallbacks = {};
	var action = function(action, args, callback, progress) {
		parent.postMessage({messageID: ++messageID, action: action, args: args}, '*');
		messageCallbacks[messageID] = callback;
		if(messageCallbacks[messageID]) messageCallbacks[messageID].progress = progress;
	};
	window.addEventListener('message', function(message) {
		if(message.source === parent) {
			if(message.data.inReplyTo) {
				var callback = messageCallbacks[message.data.inReplyTo];
				if(message.data.progress) callback = callback.progress;
				callback.apply(window, message.data.result);
				if(!message.data.progress) messageCallbacks[message.data.inReplyTo] = null;
			} else if(message.data.action) {
				airborn.listeners[message.data.action + 'Request'].forEach(function(listener) {
					listener.apply(airborn, message.data.args);
				});
			}
		} else if([].map.call(document.getElementsByTagName('iframe'), function(iframe) { return iframe.contentWindow; }).indexOf(message.source) !== -1) {
			action(message.data.action, message.data.args, function() {
				message.source.postMessage({inReplyTo: message.data.messageID, result: [].slice.call(arguments)}, '*');
			}, function() {
				message.source.postMessage({inReplyTo: message.data.messageID, result: [].slice.call(arguments), progress: true}, '*');
			});
		} else if(message.source === top) {
			console.log(document.getElementsByTagName('iframe').length);
		} else {
			console.info('unknown source');
		}
	}, false);
	airborn = laskya = {
		listeners: {
			openFileRequest: []
		},
		addEventListener: function(eventName, listener) {
			airborn.listeners[eventName].push(listener);
		}
	};
	function addAction(name) {
		var parts = name.split('.');
		var target = airborn;
		parts.slice(0, -1).forEach(function(part) {
			if(!target[part]) target[part] = {};
			target = target[part];
		});
		target[parts[parts.length - 1]] = function() {
			var args = [].slice.call(arguments);
			var firstfunction = args.map(function(arg) { return Object.prototype.toString.call(arg); }).indexOf('[object Function]');
			if(firstfunction === -1) firstfunction = args.length;
			action(name, args.slice(0, firstfunction), args[firstfunction], args[firstfunction + 1]);
		};
	}
	addAction('wm.focus');
	addAction('wm.setTitle');
	addAction('wm.setIcon');
	addAction('wm.openFile');
	addAction('wm.openWindow');
	addAction('wm.showProgress');
	addAction('wm.setProgress');
	addAction('wm.hideProgress');

	addAction('fs.getFile');
	addAction('fs.putFile');
	addAction('fs.prepareFile');
	addAction('fs.prepareString');
	addAction('fs.prepareUrl');
	addAction('fs.startTransaction');
	addAction('fs.endTransaction');
	
	navigator.mozApps = {};
	navigator.mozApps.installPackage = function() {
		var args = [].slice.call(arguments);
		var request = new DOMRequest();
		action('apps.installPackage', args, function(result, err) {
			if(err) {
				request.error = err;
				if(request.onerror) request.onerror();
			} else {
				request.result = result;
				if(request.onsuccess) request.onsuccess();
			}
		});
		return request;
	};

	var title = document.getElementsByTagName('title')[0];
	if(title) airborn.wm.setTitle(title.textContent);
	var icon = document.querySelector('link[rel="shortcut icon"], link[rel="icon"]');
	if(icon) airborn.wm.setIcon(icon.href);
	window.addEventListener('focus', function() {
		airborn.wm.focus();
	}, true);

	var requestOpen = XMLHttpRequest.prototype.open;
	var rSchema = /^[a-z]+:/i;
	var rArgs = /[?#].*$/;
	var root;
	(function() {
		var href = location.href;
		var sourceURLIndex = href.lastIndexOf('sourceURL%3D') + 12;
		var commentEndIndex = href.indexOf('%20--%3E', sourceURLIndex);
		root = decodeURIComponent(href.substring(sourceURLIndex, commentEndIndex) + href.substr(commentEndIndex + 8));
	})();
	XMLHttpRequest.prototype.open = function(method, url) {
		if(url.substr(0, 7) === 'data://' && url.indexOf(',') === -1) url = url.substr(7); // Workaround for URI.js in Firetext
		if(method === 'GET' && !rSchema.test(url)) {
			this.airbornFile = true;
			this.setRequestHeader = function() { console.log(this, arguments); };
			var codec;
			this.overrideMimeType = function(mimeType) {
				console.log(this, arguments);
				// mimeType is of the form mime/type; charset=utf-8
				if(mimeType.split('/')[0] === 'text') return;
				console.log("codec = 'arrayBuffer';");
				codec = 'arrayBuffer';
			};
{'fraction_non_alphanumeric': 0.17850759606791777, 'fraction_numerical': 0.004915102770330653, 'mean_word_length': 4.802333117303953, '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': '6452250', 'n_tokens_mistral': 3214, 'n_tokens_neox': 2900, 'n_words': 498}