<commit_before>ajax_url = 'https://kmu43f0xqb.execute-api.us-east-1.amazonaws.com/prod/posts/';
ajax_posts_url = 'posts/';

posting_delay = 10;
button_delay = 3;
auto_refresh_delay = 30000;
bulk_load_amount = 5;

postIds = [];
highest_id = null;
lowest_id = null;

function getLatestPost(){
	loading();
	var xmlhttp = new XMLHttpRequest();
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == XMLHttpRequest.DONE) {
			if (xmlhttp.status == 200) {
				var resp = JSON.parse(xmlhttp.responseText);
				console.log('Latest post: '+resp.postId);
				for (var i = 0; i < bulk_load_amount; i++){
					getPost(resp.postId - i);
				}
			} else if (xmlhttp.status == 400) {
				//TODO alert('There was an error 400');
			} else {
				//TODO alert('something else other than 200 was returned');
			}
		}
	};
	xmlhttp.open("GET", ajax_url, true);
	xmlhttp.send();
}

function getPost(postId){
	console.log('Checking: '+postId);
	if (!postId || postId < 1){
		// Too low
		return;
	}
	loading();
	var xmlhttp = new XMLHttpRequest();
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == XMLHttpRequest.DONE) {
			if (xmlhttp.status == 200) {
				console.log('Latest post: '+xmlhttp.responseText)
				addPost(JSON.parse(xmlhttp.responseText));
			} else if (xmlhttp.status == 400) {
				console.log('There was an error 400');
				//TODO alert('There was an error 400');
			} else {
				console.log('something else other than 200 was returned');
				//TODO alert('something else other than 200 was returned');
			}
			unloading();
		}
	};
	xmlhttp.open("GET", ajax_posts_url + postId + '.json', true);
	xmlhttp.send();
}

function addPost(postObj){
	// Check post not already exists<commit_msg>Prevent loading already loaded threads<commit_after>ajax_url = 'https://kmu43f0xqb.execute-api.us-east-1.amazonaws.com/prod/posts/';
ajax_posts_url = 'posts/';

posting_delay = 10;
button_delay = 3;
auto_refresh_delay = 30000;
bulk_load_amount = 5;

postIds = [];
highest_id = null;
lowest_id = null;

function getLatestPost(){
	loading();
	var xmlhttp = new XMLHttpRequest();
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == XMLHttpRequest.DONE) {
			if (xmlhttp.status == 200) {
				var resp = JSON.parse(xmlhttp.responseText);
				console.log('Latest post: '+resp.postId);
				for (var i = 0; i < bulk_load_amount; i++){
					getPost(resp.postId - i);
				}
			} else if (xmlhttp.status == 400) {
				//TODO alert('There was an error 400');
			} else {
				//TODO alert('something else other than 200 was returned');
			}
		}
	};
	xmlhttp.open("GET", ajax_url, true);
	xmlhttp.send();
}

function getPost(postId){
	console.log('Checking: '+postId);
	if (!postId || postId < 1 || postIds.indexOf(postId) > -1){
		// Too low or already loaded
		return;
	}
	loading();
	var xmlhttp = new XMLHttpRequest();
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == XMLHttpRequest.DONE) {
			if (xmlhttp.status == 200) {
				console.log('Latest post: '+xmlhttp.responseText)
				addPost(JSON.parse(xmlhttp.responseText));
			} else if (xmlhttp.status == 400) {
				console.log('There was an error 400');
				//TODO alert('There was an error 400');
			} else {
				console.log('something else other than 200 was returned');
				//TODO alert('something else other than 200 was returned');
			}
			unloading();
		}
	};
	xmlhttp.open("GET", ajax_posts_url + postId + '.json', true);
	xmlhttp.send();
}

function addPost(postObj){
	// Check post not already exists
{'fraction_non_alphanumeric': 0.15378031383737517, 'fraction_numerical': 0.025962910128388018, 'mean_word_length': 3.776566757493188, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 34}, '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': '575397', 'n_tokens_mistral': 1433, 'n_tokens_neox': 1206, 'n_words': 294}