<commit_before>Math.seedrandom();
var t, num, interval, maximized, sound, errored, reconnect, mysecret, mypublic, mtag, nickset;
t = num = interval = maximized = sound = errored = reconnect = pos = 0;
var names = new Array();
var keys = new Array();
var fingerprints = new Array();
var nick = $("#nick").html();
var focus = true;
var soundEmbed = null;

function scrolldown() {
	$("#chat").animate({ scrollTop: document.getElementById("chat").scrollHeight-20}, 500 );
}

function getstamp(nick) {
	var time = new Date();
	var h = time.getHours();
	var m = time.getMinutes();
	var spaces = "";
	for (si=0; si < (nick.length - 5); si++) {
		spaces += "&nbsp";
	}
	if (String(h).length == 1) {
		h = "0" + String(h);
	}
	if (String(m).length == 1) {
		m = "0" + String(m);
	}
	return spaces + h + ":" + m;
}

function soundPlay(which) {
	function createSound(which) {
		soundEmbed = document.createElement("audio");
		soundEmbed.setAttribute("src", which);
		soundEmbed.setAttribute("style", "display: none;");
		soundEmbed.setAttribute("autoplay", true);
	}
	if (!soundEmbed) {
		createSound(which);
	}
	else {
		document.body.removeChild(soundEmbed);
		soundEmbed.removed = true;
		soundEmbed = null;
		createSound(which);
	}
	soundEmbed.removed = false;
	document.body.appendChild(soundEmbed);
}

function gen(size) {
	var str = "";
	var charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	for (i=0; i < size; i++) {
        str += charset.charAt(Math.floor(Math.random() * charset.length));
	}
 	return str;
}

function textcounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
	}
	else {
		cntfield.value = maxlimit - field.value.length;
	}
}

function scrubtags(str) {
	return str.replace(/</g,"&lt;").replace(/>/g,"&gt;");
}

function processline(chat, flip) {
	var i = 0;
	var decrypted, corrupt, user;
	decrypted = corrupt = user = 0;
	if (chat) {
		chat = $.trim(chat);
		if (match = chat.match(/^[a-z]{1,12}:\s\[B-C\](.*)\[E-C\]$/)) {
			match = chat.match(/\[B-C\](.*)\[E-C\]/);
			decrypted = cryptico.decrypt(match[0].substring(5, match[0].length - 5), mysecret);
			if (decrypted.signature != "verified") {
				thisnick = match.match(/^[a-z]{1,12}/);
				chat = "<span class=\"nick\">" + thisnick + "</span> <span class=\"diffkey\">corrupt</span>";
				corrupt = 1;
			}
			else if (decrypted.status == "success") {
				chat = chat.replace(/\[B-C\](.*)\[E-C\]/, decrypted.plaintext.replace(/(\r\n|\n\r|\r|\n)/gm, ""));
			}
			else {
				chat = "<span class=\"diffkey\">decryption failure</span>";
				corrupt = 1;
			}
		}
		if ((!flip) || ((decrypted.status == "success") && (decrypted.signature == "verified"))) {
			chat = scrubtags(chat);
			if ((match = chat.match(/((mailto\:|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi)) && fancyurls) {
				for (mc = 0; mc <= match.length - 1; mc++) {
					var sanitize = match[mc].split("");
					for (ii = 0; ii <= sanitize.length-1; ii++) {
						if (!sanitize[ii].match(/\w|\d|\:|\/|\?|\=|\#|\+|\,|\.|\&|\;|\%/)) {
							sanitize[ii] = encodeURIComponent(sanitize[ii]);
						}
					}
					sanitize = sanitize.join("");
					chat = chat.replace(sanitize, "<a target=\"_blank\" href=\"" + install + "?redirect=" + escape(sanitize) + "\">" + match[mc] + "</a>");
				}
			}
			chat = chat.replace(/\&lt\;3/g, "<span class=\"monospace\">&#9829;</span>");
			if (match = chat.match(/^[a-z]+:\s\/me\s/)) {
				match = match[0];
				thisnick = match.match(/^[a-z]{1,12}/);
				chat = chat.replace(/^[a-z]+:\s\/me\s/, "<span class=\"nick\">* " + thisnick + " ") + " *</span>";
			}
			else if (match = chat.match(/^[a-z]{1,12}/)) {
				var stamp = getstamp(match[0]);
				chat = chat.replace(/^[a-z]+:/, "<span class=\"nick\" onmouseover=\"this.innerHTML = \'" + stamp + "\';\" onmouseout=\"this.innerHTML = \'" + match[0] + "\';\">" + match[0] + "</span>");
			}
		}
		else if ((match = chat.match(/^(\&gt\;|\&lt\;) [a-z]{1,12} (has arrived|has left)$/))) {
			chat = "<span class=\"nick\">" + match[0] + "</span>";
			user = 1;
			updatekeys();
			updatechatters();
		}
		else if (thisnick = chat.match(/^[a-z]{1,12}/)) {
			chat = "<span class=\"nick\">" + thisnick + "</span> <span class=\"diffkey\">corrupt</span>";
			corrupt = 1;
		}
		else {
			chat = "<span class=\"diffkey\">corrupt</span>"
			corrupt = 1;
		}
		if (user) {
			tag = "u";
		}
		else if (corrupt) {
			tag = "c";
		}
		else {
			tag = "";
		}
		if (mtag) {
			tag += "gsm";
			mtag = 0;
		}
		else {
			tag += "msg";
			mtag = 1;
		}
		chat = "<div class=\"" + tag + "\"><div class=\"text\">" + chat + "</div></div>";
	}
	return chat;
}

function updatekeys() {
	$.ajax( { url: "index.php",
		type: "POST",
		async: false,
		data: "nick=" + $("#nickinput").val() + "&name=" + $("#name").val() + "&public=get",
		success: function(data) {
			data = data.split('|');
			oldnames = names;
			oldkeys = keys;
			names = new Array();
			keys = new Array();
			fingerprints = new Array();
			for (i=0; i <= data.length - 1; i++) {
				keymatch = data[i].match(/^[a-z]{1,12}:/);
				names[i] = keymatch[0].substring(0, keymatch[0].length - 1);
				keymatch = data[i].match(/:.+/);
				keys[i] = decodeURIComponent(keymatch[0].substring(1));
				if (keys[i].length != 100) {
					fingerprints[i] = "<span class=\"red\">invalid key - do not trust.</span>";
					$("#fingerlink").click();
				}
				var loc = jQuery.inArray(names[i], oldnames);
				if ((names[i] == oldnames[loc]) && (keys[i] != oldkeys[loc])) {
					fingerprints[i] = "<span class=\"red\">tampered key - do not trust.</span>";
					$("#fingerlink").click();
				}
				else {
					var shaObj = new jsSHA(keys[i], "ASCII");
					fingerprints[i] = shaObj.getHash("SHA-512", "HEX");
					fingerprints[i] = fingerprints[i].substring(0, 8).toUpperCase() + ":" + fingerprints[i].substring(40, 48).toUpperCase() + ":" + fingerprints[i].substring(70, 78).toUpperCase() + ":" + fingerprints[i].substring(95, 103).toUpperCase() + ":" + fingerprints[i].substring(120, 128).toUpperCase();
				}
			}
		}
	});
	var fingerhtml = "Verify chatters using their key fingerprint. <br />(You can verify fingerprints over the phone.)<br /><br />";
	for (fi=0; fi <= names.length - 1; fi++) {
		var nbsp = "";
		for (ni=0; ni + names[fi].length != 12; ni++) {
			nbsp += "&nbsp";
		}
		fingerhtml += "<span class=\"blue\">" + names[fi] + "</span> " + nbsp + fingerprints[fi] + "<br />";
	}
	fingerhtml += "<br /><br /><span onclick=\"fingerclose();\" id=\"close\">close</span>"; 
	$("#fingerprints").html(fingerhtml);
}

function updatechat(div){
	$(div).load("index.php?chat=" + name + "&pos=" + pos, function() {
		if ($("#loader").html() == "NOEXIST") {
			if (!errored && mypublic) {
				errordisplay("your chat no longer exists.");
			}
		}
		else if ($("#loader").html() == "NOLOGIN") {
			if (!errored && mypublic) {
				errordisplay("you have been logged out.");<commit_msg>Tweaks<commit_after>Math.seedrandom();
var t, num, interval, maximized, sound, errored, reconnect, mysecret, mypublic, mtag, nickset;
t = num = interval = maximized = sound = errored = reconnect = pos = 0;
var names = new Array();
var keys = new Array();
var fingerprints = new Array();
var nick = $("#nick").html();
var focus = true;
var soundEmbed = null;

function scrolldown() {
	$("#chat").animate({ scrollTop: document.getElementById("chat").scrollHeight-20}, 500 );
}

function getstamp(nick) {
	var time = new Date();
	var h = time.getHours();
	var m = time.getMinutes();
	var spaces = "";
	for (si=0; si < (nick.length - 5); si++) {
		spaces += "&nbsp";
	}
	if (String(h).length == 1) {
		h = "0" + String(h);
	}
	if (String(m).length == 1) {
		m = "0" + String(m);
	}
	return spaces + h + ":" + m;
}

function soundPlay(which) {
	function createSound(which) {
		soundEmbed = document.createElement("audio");
		soundEmbed.setAttribute("src", which);
		soundEmbed.setAttribute("style", "display: none;");
		soundEmbed.setAttribute("autoplay", true);
	}
	if (!soundEmbed) {
		createSound(which);
	}
	else {
		document.body.removeChild(soundEmbed);
		soundEmbed.removed = true;
		soundEmbed = null;
		createSound(which);
	}
	soundEmbed.removed = false;
	document.body.appendChild(soundEmbed);
}

function gen(size) {
	var str = "";
	var charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	for (i=0; i < size; i++) {
        str += charset.charAt(Math.floor(Math.random() * charset.length));
	}
 	return str;
}

function textcounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
	}
	else {
		cntfield.value = maxlimit - field.value.length;
	}
}

function scrubtags(str) {
	return str.replace(/</g,"&lt;").replace(/>/g,"&gt;");
}

function processline(chat, flip) {
	var i = 0;
	var decrypted, corrupt, user;
	decrypted = corrupt = user = 0;
	if (chat) {
		chat = $.trim(chat);
		if (match = chat.match(/^[a-z]{1,12}:\s\[B-C\](.*)\[E-C\]$/)) {
			match = chat.match(/\[B-C\](.*)\[E-C\]/);
			decrypted = cryptico.decrypt(match[0].substring(5, match[0].length - 5), mysecret);
			if (decrypted.signature != "verified") {
				thisnick = match.match(/^[a-z]{1,12}/);
				chat = "<span class=\"nick\">" + thisnick + "</span> <span class=\"diffkey\">corrupt</span>";
				corrupt = 1;
			}
			else if (decrypted.status == "success") {
				chat = chat.replace(/\[B-C\](.*)\[E-C\]/, decrypted.plaintext.replace(/(\r\n|\n\r|\r|\n)/gm, ""));
			}
			else {
				chat = "<span class=\"diffkey\">decryption failure</span>";
				corrupt = 1;
			}
		}
		if ((!flip) || ((decrypted.status == "success") && (decrypted.signature == "verified"))) {
			chat = scrubtags(chat);
			if ((match = chat.match(/((mailto\:|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi)) && fancyurls) {
				for (mc = 0; mc <= match.length - 1; mc++) {
					var sanitize = match[mc].split("");
					for (ii = 0; ii <= sanitize.length-1; ii++) {
						if (!sanitize[ii].match(/\w|\d|\:|\/|\?|\=|\#|\+|\,|\.|\&|\;|\%/)) {
							sanitize[ii] = encodeURIComponent(sanitize[ii]);
						}
					}
					sanitize = sanitize.join("");
					chat = chat.replace(sanitize, "<a target=\"_blank\" href=\"" + install + "?redirect=" + escape(sanitize) + "\">" + match[mc] + "</a>");
				}
			}
			chat = chat.replace(/\&lt\;3/g, "<span class=\"monospace\">&#9829;</span>");
			if (match = chat.match(/^[a-z]+:\s\/me\s/)) {
				match = match[0];
				thisnick = match.match(/^[a-z]{1,12}/);
				chat = chat.replace(/^[a-z]+:\s\/me\s/, "<span class=\"nick\">* " + thisnick + " ") + " *</span>";
			}
			else if (match = chat.match(/^[a-z]{1,12}/)) {
				var stamp = getstamp(match[0]);
				chat = chat.replace(/^[a-z]+:/, "<span class=\"nick\" onmouseover=\"this.innerHTML = \'" + stamp + "\';\" onmouseout=\"this.innerHTML = \'" + match[0] + "\';\">" + match[0] + "</span>");
			}
		}
		else if ((match = chat.match(/^(\&gt\;|\&lt\;) [a-z]{1,12} (has arrived|has left)$/))) {
			chat = "<span class=\"nick\">" + match[0] + "</span>";
			user = 1;
			updatekeys();
			updatechatters();
		}
		else if (thisnick = chat.match(/^[a-z]{1,12}/)) {
			chat = "<span class=\"nick\">" + thisnick + "</span> <span class=\"diffkey\">corrupt</span>";
			corrupt = 1;
		}
		else {
			chat = "<span class=\"diffkey\">corrupt</span>"
			corrupt = 1;
		}
		if (user) {
			tag = "u";
		}
		else if (corrupt) {
			tag = "c";
		}
		else {
			tag = "";
		}
		if (mtag) {
			tag += "gsm";
			mtag = 0;
		}
		else {
			tag += "msg";
			mtag = 1;
		}
		chat = "<div class=\"" + tag + "\"><div class=\"text\">" + chat + "</div></div>";
	}
	return chat;
}

function updatekeys() {
	$.ajax( { url: "index.php",
		type: "POST",
		async: false,
		data: "nick=" + $("#nickinput").val() + "&name=" + $("#name").val() + "&public=get",
		success: function(data) {
			data = data.split('|');
			oldnames = names;
			oldkeys = keys;
			names = new Array();
			keys = new Array();
			fingerprints = new Array();
			for (i=0; i <= data.length - 1; i++) {
				keymatch = data[i].match(/^[a-z]{1,12}:/);
				names[i] = keymatch[0].substring(0, keymatch[0].length - 1);
				keymatch = data[i].match(/:.+/);
				keys[i] = decodeURIComponent(keymatch[0].substring(1));
				if (keys[i].length != 100) {
					var nbsp = "";
					for (ni=0; ni != 17; ni++) {
						nbsp += "&nbsp";
					}
					fingerprints[i] = nbsp + " <span class=\"red\">invalid key - do not trust.</span>";
					$("#fingerlink").click();
				}
				var loc = jQuery.inArray(names[i], oldnames);
				if ((names[i] == oldnames[loc]) && (keys[i] != oldkeys[loc])) {
					var nbsp = "";
					for (ni=0; ni != 16; ni++) {
						nbsp += "&nbsp";
					}
					fingerprints[i] = nbsp + " <span class=\"red\">tampered key - do not trust.</span>";
					$("#fingerlink").click();
				}
				else {
					var shaObj = new jsSHA(keys[i], "ASCII");
					fingerprints[i] = shaObj.getHash("SHA-512", "HEX");
					fingerprints[i] = fingerprints[i].substring(0, 8).toUpperCase() + ":" + fingerprints[i].substring(40, 48).toUpperCase() + ":" + fingerprints[i].substring(70, 78).toUpperCase() + ":" + fingerprints[i].substring(95, 103).toUpperCase() + ":" + fingerprints[i].substring(120, 128).toUpperCase();
				}
			}
		}
	});
	var fingerhtml = "Verify chatters using their key fingerprint. <br />(You can verify fingerprints over the phone.)<br /><br />";
	for (fi=0; fi <= names.length - 1; fi++) {
		var nbsp = "";
		for (ni=0; ni + names[fi].length != 13; ni++) {
			nbsp += "&nbsp";
		}
		fingerhtml += "<span class=\"blue\">" + names[fi] + "</span> " + nbsp + " " + fingerprints[fi] + "<br />";
	}
	fingerhtml += "<br /><br /><span onclick=\"fingerclose();\" id=\"close\">close</span>"; 
	$("#fingerprints").html(fingerhtml);
}

function updatechat(div){
	$(div).load("index.php?chat=" + name + "&pos=" + pos, function() {
		if ($("#loader").html() == "NOEXIST") {
			if (!errored && mypublic) {
				errordisplay("your chat no longer exists.");
			}
		}
		else if ($("#loader").html() == "NOLOGIN") {
			if (!errored && mypublic) {
				errordisplay("you have been logged out.");
{'fraction_non_alphanumeric': 0.2443242473845278, 'fraction_numerical': 0.016511280335919153, 'mean_word_length': 3.2946210268948657, 'pattern_counts': {'":': 10, '<': 97, '<?xml version=': 0, '>': 87, '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': '6141816', 'n_tokens_mistral': 6062, 'n_tokens_neox': 5261, 'n_words': 1063}