<commit_before>// NOTE: This script requires ECMAScript 6 support (uses `const`)


var inputs;

const me = document.currentScript;
const typeToCallback = {
	'button': {
		'eventName': 'click',
		'callback': buttonCallback()
	},
	'checkbox': {
		'eventName': 'change',
		'callback': checkboxCallback
	},
	'email': {
		'eventName': 'change',
		'callback': emailCallback
	},
	'file': {
		'eventName': 'change',
		'callback': fileCallback
	},
	'password': {
		'eventName': 'change',
		'callback': passwordCallback
	},
	'radio': {
		'eventName': 'change',
		'callback': radioCallback
	},
	'range': {
		'eventName': 'change',
		'callback': rangeCallback
	},
	'reset': {
		'eventName': 'click',
		'callback': resetCallback
	},
	'search': {
		'eventName': 'change',
		'callback': searchCallback
	},
	'submit': {
		'eventName': 'click',
		'callback': submitCallback
	},
	'tel': {
		'eventName': 'change',
		'callback': telCallback
	},
	'text': {
		'eventName': 'change',
		'callback': textCallback
	},
	'hidden': {
		'eventName': 'change',
		'callback': hiddenCallback
	},
	'image': {
		'eventName': 'click',
		'callback': imageCallback
	},
	'url': {
		'eventName': 'change',
		'callback': urlCallback
	}
};


window.onload = function() {
	inputs = document.getElementsByTagName('input');

	for(var i = 0; i < inputs.length; ++i) {
		const input = inputs[i];
		const type = input.getAttribute('type');

		const nameWithCallback = typeToCallback[type];

		input.nextElementSibling.textContent = type[0].toUpperCase() + type.substr(1);
		if(nameWithCallback !== undefined)
			input.addEventListener(nameWithCallback.eventName, nameWithCallback.callback)

		if('autocomplete' in input)
			input.autocomplete = true;

		const typeSupportedByBrowser = inputTypeSupported(type);
		const typeSupportedByDemonstation = type in typeToCallback;
		if(!typeSupportedByBrowser || !typeSupportedByDemonstation) {
			const descriptionNode = document.createElement('SPAN')
			const textNode = document.createTextNode((typeSupportedByBrowser ? '' : '!NOT SUPPORTED IN THIS BROWSER!') + (typeSupportedByDemonstation ? '' : ' !NOT SUPPORTED BY THE DEMONSTRATION!'));
			descriptionNode.appendChild(textNode);
			descriptionNode.className = 'unsupported';

			input.parentNode.insertBefore(descriptionNode, input.nextElementSibling);
		}
	};
}


// Based on http://stackoverflow.com/a/21840624/2851815
function inputTypeSupported(type) {
	try {
		var elem = document.createElement('input');
		elem.type = type;
		if(elem.type === type)
			return true;
	} catch(e) {}

	return false;
}


// For data encapsulation (`ctr` and `launched` not at global scope)
function buttonCallback() {
	var ctr;
	var launched = false;

	return function(e) {
		ctr = (Math.random() * 1000).toFixed();

		// Timeout-chain is forever, once launched
		const cbk = function() {
			if(ctr > 0)
				e.originalTarget.value = ctr-- + 'ms';
			else
				e.originalTarget.value = '';
			setTimeout(cbk, 1);
		};

		if(!launched) {
			launched = true;
			cbk();
		}
	}
}

function checkboxCallback(e) {
	const input = e.originalTarget;
	var descriptionNode = input.nextElementSibling;

	// Dynamically append description node
	if(descriptionNode.className !== '') {
		const after = descriptionNode;

		descriptionNode = document.createElement('SPAN');
		descriptionNode.appendChild(document.createTextNode(''));

		input.parentNode.insertBefore(descriptionNode, after);
	}

	descriptionNode.textContent = input.checked;
}<commit_msg>Fix `buttonCallback()` overloading CPU/thread count, time left goes down by 3ms at a time<commit_after>// NOTE: This script requires ECMAScript 6 support (uses `const`)


var inputs;

const me = document.currentScript;
const typeToCallback = {
	'button': {
		'eventName': 'click',
		'callback': buttonCallback()
	},
	'checkbox': {
		'eventName': 'change',
		'callback': checkboxCallback
	},
	'email': {
		'eventName': 'change',
		'callback': emailCallback
	},
	'file': {
		'eventName': 'change',
		'callback': fileCallback
	},
	'password': {
		'eventName': 'change',
		'callback': passwordCallback
	},
	'radio': {
		'eventName': 'change',
		'callback': radioCallback
	},
	'range': {
		'eventName': 'change',
		'callback': rangeCallback
	},
	'reset': {
		'eventName': 'click',
		'callback': resetCallback
	},
	'search': {
		'eventName': 'change',
		'callback': searchCallback
	},
	'submit': {
		'eventName': 'click',
		'callback': submitCallback
	},
	'tel': {
		'eventName': 'change',
		'callback': telCallback
	},
	'text': {
		'eventName': 'change',
		'callback': textCallback
	},
	'hidden': {
		'eventName': 'change',
		'callback': hiddenCallback
	},
	'image': {
		'eventName': 'click',
		'callback': imageCallback
	},
	'url': {
		'eventName': 'change',
		'callback': urlCallback
	}
};


window.onload = function() {
	inputs = document.getElementsByTagName('input');

	for(var i = 0; i < inputs.length; ++i) {
		const input = inputs[i];
		const type = input.getAttribute('type');

		const nameWithCallback = typeToCallback[type];

		input.nextElementSibling.textContent = type[0].toUpperCase() + type.substr(1);
		if(nameWithCallback !== undefined)
			input.addEventListener(nameWithCallback.eventName, nameWithCallback.callback)

		if('autocomplete' in input)
			input.autocomplete = true;

		const typeSupportedByBrowser = inputTypeSupported(type);
		const typeSupportedByDemonstation = type in typeToCallback;
		if(!typeSupportedByBrowser || !typeSupportedByDemonstation) {
			const descriptionNode = document.createElement('SPAN')
			const textNode = document.createTextNode((typeSupportedByBrowser ? '' : '!NOT SUPPORTED IN THIS BROWSER!') + (typeSupportedByDemonstation ? '' : ' !NOT SUPPORTED BY THE DEMONSTRATION!'));
			descriptionNode.appendChild(textNode);
			descriptionNode.className = 'unsupported';

			input.parentNode.insertBefore(descriptionNode, input.nextElementSibling);
		}
	};
}


// Based on http://stackoverflow.com/a/21840624/2851815
function inputTypeSupported(type) {
	try {
		var elem = document.createElement('input');
		elem.type = type;
		if(elem.type === type)
			return true;
	} catch(e) {}

	return false;
}


// For data encapsulation (`ctr` and `launched` not at global scope)
function buttonCallback() {
	var ctr;
	var launched = false;

	return function(e) {
		ctr = (Math.random() * 1000).toFixed();

		// Timeout-chain is forever, once launched
		const cbk = function() {
			if(ctr > 0) {
				e.originalTarget.value = ctr + 'ms';
				ctr = Math.max(0, ctr - 3);
			} else
				e.originalTarget.value = '';
			setTimeout(cbk, 3);
		};

		if(!launched) {
			launched = true;
			cbk();
		}
	}
}

function checkboxCallback(e) {
	const input = e.originalTarget;
	var descriptionNode = input.nextElementSibling;

	// Dynamically append description node
	if(descriptionNode.className !== '') {
		const after = descriptionNode;

		descriptionNode = document.createElement('SPAN');
		descriptionNode.appendChild(document.createTextNode(''));

		input.parentNode.insertBefore(descriptionNode, after);
	}

	descriptionNode.textContent = input.checked;
}
{'fraction_non_alphanumeric': 0.15376984126984128, 'fraction_numerical': 0.007511337868480726, 'mean_word_length': 4.526233359436178, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5985357', 'n_tokens_mistral': 2508, 'n_tokens_neox': 2259, 'n_words': 495}