<commit_before>(function() {
var
	main = document.querySelector("main"),
	itemsPocket = document.querySelector("#items #items-pockets"),
	itemsAround = document.querySelector("#items #items-around"),

	type_timeout,
	startDelay = 2500,
	scrollCheckerDelay = 5000,

	typeVariability = 3,
	speedUp = 0.5,

	errorCharProbability = 0.01,
	longChar = 500,
	mediumChar = 200,
	shortChar = 50,
$;

/**
 * Shorthand function for XMLHttpRequest.
 */
function x(method, command, obj, callback) {
	var 
		xhr = new XMLHttpRequest(),
		url = command + ".php",
	$;

	xhr.open(method, url, true);
	xhr.addEventListener("load", callback);

	xhr.setRequestHeader("Accept", "application/json");
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

	xhr.send(obj);
}

function newParagraph() {
	var p = document.createElement("p");
	p.classList.add("stale");
	main.appendChild(p);

	return p;
}

function scrollChecker() {
	var 
		p = main.lastChild,
		y = p.offsetTop + p.offsetHeight - main.scrollTop,
	$;
	// Check that the paragraph is nearing the bottom of the screen.
	if(y > window.innerHeight * 0.6) {
		scrollMain();
	}
	else {
		setTimeout(scrollChecker, scrollCheckerDelay);
	}
}

function scrollMain(dt) {
	var 
		currentScroll = main.scrollTop++,
	$;

	// Disable auto scroller if user has moved the scroll up.
	if(main.hasAttribute("data-scroll")) {
		if(main.scrollTop < main.getAttribute("data-scroll")) {
			setTimeout(scrollChecker, scrollCheckerDelay);
			return;
		}
	}

	if(main.scrollTop != currentScroll) {
		main.setAttribute("data-scroll", main.scrollTop);
		requestAnimationFrame(scrollMain);
	}
	else {
		setTimeout(scrollChecker, scrollCheckerDelay);
	}
}

/**
 * Self-invoking function used to initiate typing a message to the main output.
 */
function type(msg, addTo, delay) {
	var
		chars = (msg instanceof Array)
			? msg
			: msg.split(""),
		c,
		t,
	$;

	if(!addTo) {
		addTo = newParagraph();
	}

	if(delay) {
		type_timeout = setTimeout(function() {
			type(msg, addTo);
		}, delay);

		return;
	}


	if(chars[0]
	&& chars[0].charCodeAt(0) >= 97 
	&& chars[0].charCodeAt(0) <= 97 + 26) {
		if(Math.random() <= errorCharProbability) {
			addTo.innerHTML += String.fromCharCode(
				Math.round(97 + (Math.random() * 26))
			);
			
			setTimeout(function() {
				addTo.innerHTML = addTo.innerHTML.substring(0, 
					addTo.innerHTML.length - 1);

				setTimeout(function() {<commit_msg>Pause typing when user scrolls back.<commit_after>(function() {
var
	pause = false,
	main = document.querySelector("main"),
	itemsPocket = document.querySelector("#items #items-pockets"),
	itemsAround = document.querySelector("#items #items-around"),

	type_timeout,
	startDelay = 2500,
	scrollCheckerDelay = 5000,

	typeVariability = 3,
	speedUp = 0.5,

	errorCharProbability = 0.01,
	longChar = 500,
	mediumChar = 200,
	shortChar = 50,
$;

/**
 * Shorthand function for XMLHttpRequest.
 */
function x(method, command, obj, callback) {
	var 
		xhr = new XMLHttpRequest(),
		url = command + ".php",
	$;

	xhr.open(method, url, true);
	xhr.addEventListener("load", callback);

	xhr.setRequestHeader("Accept", "application/json");
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

	xhr.send(obj);
}

function newParagraph() {
	var p = document.createElement("p");
	p.classList.add("stale");
	main.appendChild(p);

	return p;
}

function scrollChecker() {
	var 
		p = main.lastChild,
		y = p.offsetTop + p.offsetHeight - main.scrollTop,
	$;

	pause = false;

	// Check that the paragraph is nearing the bottom of the screen.
	if(y > window.innerHeight * 0.6) {
		scrollMain();
	}
	else {
		setTimeout(scrollChecker, scrollCheckerDelay);
	}
}

function scrollMain(dt) {
	var 
		currentScroll = main.scrollTop++,
	$;

	// Disable auto scroller if user has moved the scroll up.
	if(main.hasAttribute("data-scroll")) {
		if(main.scrollTop < main.getAttribute("data-scroll")) {
			pause = true;
			setTimeout(scrollChecker, scrollCheckerDelay);
			return;
		}
	}

	if(main.scrollTop != currentScroll) {
		main.setAttribute("data-scroll", main.scrollTop);
		requestAnimationFrame(scrollMain);
	}
	else {
		setTimeout(scrollChecker, scrollCheckerDelay);
	}
}

/**
 * Self-invoking function used to initiate typing a message to the main output.
 */
function type(msg, addTo, delay) {
	var
		chars = (msg instanceof Array)
			? msg
			: msg.split(""),
		c,
		t,
	$;

	if(pause && chars && chars[0] == "\n") {
		setTimeout(function() {
			type(msg, addTo, delay);
		}, 1000);
		return;
	}

	if(!addTo) {
		addTo = newParagraph();
	}

	if(delay) {
		type_timeout = setTimeout(function() {
			type(msg, addTo);
		}, delay);

		return;
	}


	if(chars[0]
	&& chars[0].charCodeAt(0) >= 97 
	&& chars[0].charCodeAt(0) <= 97 + 26) {
		if(Math.random() <= errorCharProbability) {
			addTo.innerHTML += String.fromCharCode(
				Math.round(97 + (Math.random() * 26))
			);
			
			setTimeout(function() {
				addTo.innerHTML = addTo.innerHTML.substring(0, 
					addTo.innerHTML.length - 1);

				setTimeout(function() {
{'fraction_non_alphanumeric': 0.1537242472266244, 'fraction_numerical': 0.017234548335974643, 'mean_word_length': 3.9258536585365853, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '160817', 'n_tokens_mistral': 1954, 'n_tokens_neox': 1749, 'n_words': 365}