<commit_before>const ping_delay = 60; // in seconds

const color_border = '#FF9900';
const color_hover = '#FFFFCC';

const attr_trans_id = '_translation_id';

var edited_node = null;
var linked_nodes = new Array();
var original_text;

function endEditionEvent(clickOK) {
	if (window.edited_node == null)
		return;

	var id = window.edited_node.getAttribute(attr_trans_id);
	var next_node = null;

	var new_text = edit_window.document.getElementById('modified').value;

	if (clickOK && new_text) {
		var not_mark = edit_window.document.getElementById('not_mark').checked;

		source_strings[id] = new_text;

		var send_ok = false;

		var xml_http = new XMLHttpRequest();

		var encoded_text = encodeURI(new_text).replace(/&/g, '%26');

		xml_http.open('POST', base_url + '/block_edit.php', false);
		xml_http.setRequestHeader('Content-Type',
			'application/x-www-form-urlencoded');
		xml_http.send('edit_doc=' + doc_id + '&edit_string=' + id +
			'&edit_text=' + encoded_text + '&dont_mark_fuzzy=' + (not_mark ? '1' : '0'));

		edit_window.focus();

		var resp = xml_http.responseText;

		if (resp.substring(0, 7) == 'badxml ')
			edit_window.alert('The server rejected the translation because of XML ' +
				"parsing errors :\n" + xml_http.responseText.substring(3) +
				"\n" + 'Check the XML tags used in your translation.');
		else if (resp.substring(0, 6) == 'interr')
			edit_window.alert('The original XML code seems corrupt. Please contact ' +
			'an administrator.' + "\n");
		else if (resp.substring(0, 2) != 'ok')
			edit_window.alert('There was an error sending the translation. Please ' +
			'retry.' + "\n" + xml_http.responseText);
		else
			send_ok = true;

		for (var i = 0 ; i < linked_nodes[id].length ; i++) {
			linked_nodes[id][i].innerHTML = new_text;
			linked_nodes[id][i].style.backgroundColor = null;
		}

		if (!send_ok) {
			edit_window.focus();
			return;
		}

	} else {
		window.edited_node.innerHTML = source_strings[id];
	}

	edit_window.close();
	edit_window = null;
	window.edited_node = null;

	// Refresh the statistics
	xml_http = new XMLHttpRequest();
	xml_http.open('GET', base_url + '/update_stats.php?doc_id=' + doc_id, true);
	xml_http.send(null);
}<commit_msg>block_edit_tool: Use asynchronous XHRs instead of synchronous ones.<commit_after>const ping_delay = 60; // in seconds

const color_border = '#FF9900';
const color_hover = '#FFFFCC';

const attr_trans_id = '_translation_id';

var edited_node = null;
var linked_nodes = new Array();
var original_text;

function endEditionEvent(clickOK) {
	if (window.edited_node == null)
		return;

	var id = window.edited_node.getAttribute(attr_trans_id);
	var next_node = null;

	var new_text = edit_window.document.getElementById('modified').value;

	if (clickOK && new_text) {
		var not_mark = edit_window.document.getElementById('not_mark').checked;

		source_strings[id] = new_text;

		var send_ok = false;

		var xml_http = new XMLHttpRequest();

		var encoded_text = encodeURI(new_text).replace(/&/g, '%26');

		xml_http.open('POST', base_url + '/block_edit.php', true);
		xml_http.setRequestHeader('Content-Type',
			'application/x-www-form-urlencoded');
		xml_http.addEventListener("load", editSaveFinished);
		xml_http.send('edit_doc=' + doc_id + '&edit_string=' + id +
			'&edit_text=' + encoded_text + '&dont_mark_fuzzy=' + (not_mark ? '1' : '0'));

		xml_http.userguide_string_id = id;
		xml_http.userguide_new_text = new_text;
		return;
	} else {
		window.edited_node.innerHTML = source_strings[id];
	}

	edit_window.close();
	edit_window = null;
	window.edited_node = null;
}

function editSaveFinished() {
	edit_window.focus();

	var resp = this.responseText,
		id = this.userguide_string_id,
		new_text = this.userguide_new_text;

	var send_ok;
	if (resp.substring(0, 7) == 'badxml ')
		edit_window.alert('The server rejected the translation because of XML ' +
			"parsing errors :\n" + this.responseText.substring(3) +
			"\n" + 'Check the XML tags used in your translation.');
	else if (resp.substring(0, 6) == 'interr')
		edit_window.alert('The original XML code seems corrupt. Please contact ' +
		'an administrator.' + "\n");
	else if (resp.substring(0, 2) != 'ok')
		edit_window.alert('There was an error sending the translation. Please ' +
		'retry.' + "\n" + this.responseText);
	else
		send_ok = true;

	for (var i = 0 ; i < linked_nodes[id].length ; i++) {
		linked_nodes[id][i].innerHTML = new_text;
		linked_nodes[id][i].style.backgroundColor = null;
	}

	if (!send_ok) {
		edit_window.focus();
		return;
	}

	edit_window.close();
	edit_window = null;
	window.edited_node = null;

	// Refresh the statistics
	xml_http = new XMLHttpRequest();
	xml_http.open('GET', base_url + '/update_stats.php?doc_id=' + doc_id, true);
	xml_http.send(null);
}
{'fraction_non_alphanumeric': 0.14670029424127784, 'fraction_numerical': 0.007566204287515763, 'mean_word_length': 4.463834672789897, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 22}, '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': '3935040', 'n_tokens_mistral': 1798, 'n_tokens_neox': 1652, 'n_words': 371}