<commit_before>var htmlSrc = document.getElementById( 'html-src' );
var cssSrc  = document.getElementById( 'css-src' );
var jsSrc   = document.getElementById( 'js-src' );

htmlSrc.value = localStorage[ 'htmlSrc' ] || '';
cssSrc.value  = localStorage[ 'cssSrc' ] || '';
jsSrc.value   = localStorage[ 'jsSrc' ] || '';

// Set up Code Mirror editors
var htmlCM = CodeMirror.fromTextArea(htmlSrc, {
	value: htmlSrc.value,
	mode: 'htmlmixed'
});
var cssCM = CodeMirror.fromTextArea(cssSrc, {
	value: cssSrc.value,
	mode: 'css'
});
var jsCM = CodeMirror.fromTextArea(jsSrc, {
	value: jsSrc.value,
	mode: 'javascript'
});

var htmlOutput    = document.getElementById( 'html-output' );
var consoleOutput = document.getElementById( 'console-output' );

// Not needed now the function runs on change of the CodeMirror Editor
//
// [ htmlSrc, cssSrc, jsSrc ].forEach( function( src ) {
	
// 	src.addEventListener( 'keyup', onUpdate );

// 	src.addEventListener( 'keydown', function(e){
// 		if(e.keyCode==9 || e.which==9){
// 			e.preventDefault();
// 			var s = this.selectionStart;
// 			this.value = this.value.substring(0,this.selectionStart) + "  " + this.value.substring(this.selectionEnd);
// 			this.selectionEnd = s + 2; 
// 		}
// 	} );

// 	src.setAttribute( 'spellcheck', false );

// } );

cssCM.on('change', onUpdate);
htmlCM.on('change', onUpdate);
jsCM.on('change', onUpdate);

updateSources();

autoClearConsole = document.getElementById( 'autoClearConsole' );
autoClearConsole.checked = localStorage[ 'autoClearConsole' ] === 'true';

var updateTimeout = null;

function onUpdate() {

	// Save Code Mirror editor to textarea
	cssCM.save();
	htmlCM.save();
	jsCM.save();
	
	localStorage[ 'htmlSrc' ] = htmlSrc.value;
	localStorage[ 'cssSrc' ]  = cssSrc.value;
	localStorage[ 'jsSrc' ]   = jsSrc.value;
	
	if( updateTimeout ) clearTimeout( updateTimeout );

	updateTimeout = setTimeout( updateSources, 500 );

}

var sandbox = null;

function updateSources() {

	if( autoClearConsole.checked ) {
		clearConsole();
	}

	if( sandbox ) {
		var evalData = {
			message: 'eval',
			source: jsSrc.value
		}
		sandbox.postMessage( JSON.stringify( evalData ), '*' );
	}

	var res = htmlSrc.value;
	res += '<style>' + cssSrc.value + '<\/style>';
	res += '<script>' + inject.toString() + ';inject();<\/script>';
	res += '<script>' + jsSrc.value + '<\/script>';

	htmlOutput.src = "data:text/html;charset=utf-8," + escape( res );<commit_msg>fixed unicode issue<commit_after>var htmlSrc = document.getElementById( 'html-src' );
var cssSrc  = document.getElementById( 'css-src' );
var jsSrc   = document.getElementById( 'js-src' );

htmlSrc.value = localStorage[ 'htmlSrc' ] || '';
cssSrc.value  = localStorage[ 'cssSrc' ] || '';
jsSrc.value   = localStorage[ 'jsSrc' ] || '';

// Set up Code Mirror editors
var htmlCM = CodeMirror.fromTextArea(htmlSrc, {
	value: htmlSrc.value,
	mode: 'htmlmixed'
});
var cssCM = CodeMirror.fromTextArea(cssSrc, {
	value: cssSrc.value,
	mode: 'css'
});
var jsCM = CodeMirror.fromTextArea(jsSrc, {
	value: jsSrc.value,
	mode: 'javascript'
});

var htmlOutput    = document.getElementById( 'html-output' );
var consoleOutput = document.getElementById( 'console-output' );

// Not needed now the function runs on change of the CodeMirror Editor
//
// [ htmlSrc, cssSrc, jsSrc ].forEach( function( src ) {
	
// 	src.addEventListener( 'keyup', onUpdate );

// 	src.addEventListener( 'keydown', function(e){
// 		if(e.keyCode==9 || e.which==9){
// 			e.preventDefault();
// 			var s = this.selectionStart;
// 			this.value = this.value.substring(0,this.selectionStart) + "  " + this.value.substring(this.selectionEnd);
// 			this.selectionEnd = s + 2; 
// 		}
// 	} );

// 	src.setAttribute( 'spellcheck', false );

// } );

cssCM.on('change', onUpdate);
htmlCM.on('change', onUpdate);
jsCM.on('change', onUpdate);

updateSources();

autoClearConsole = document.getElementById( 'autoClearConsole' );
autoClearConsole.checked = localStorage[ 'autoClearConsole' ] === 'true';

var updateTimeout = null;

function onUpdate() {

	// Save Code Mirror editor to textarea
	cssCM.save();
	htmlCM.save();
	jsCM.save();
	
	localStorage[ 'htmlSrc' ] = htmlSrc.value;
	localStorage[ 'cssSrc' ]  = cssSrc.value;
	localStorage[ 'jsSrc' ]   = jsSrc.value;
	
	if( updateTimeout ) clearTimeout( updateTimeout );

	updateTimeout = setTimeout( updateSources, 500 );

}

var sandbox = null;

function updateSources() {

	if( autoClearConsole.checked ) {
		clearConsole();
	}

	if( sandbox ) {
		var evalData = {
			message: 'eval',
			source: jsSrc.value
		}
		sandbox.postMessage( JSON.stringify( evalData ), '*' );
	}

	var res = htmlSrc.value;
	res += '<style>' + cssSrc.value + '<\/style>';
	res += '<script>' + inject.toString() + ';inject();<\/script>';
	res += '<script>' + jsSrc.value + '<\/script>';

	htmlOutput.src = "data:text/html;charset=utf-8," + encodeURIComponent( res );
{'fraction_non_alphanumeric': 0.1751227495908347, 'fraction_numerical': 0.0032733224222585926, 'mean_word_length': 4.0663212435233165, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '1236814', 'n_tokens_mistral': 1728, 'n_tokens_neox': 1660, 'n_words': 356}