<commit_before>window.onload = () => {
	loadContent(
		document.getElementsByClassName('selected'),
		'movies',
		'list'	
	)
};

bodyonload = () => {	

};

search = (elem) => {
	if (elem.value.length >= 3){
		loadContent(
			elem,
			document.getElementsByClassName('selected')[0].classList.item(0),
			'search'
		);
	} else {
		loadContent(
			elem,
			document.getElementsByClassName('selected')[0].classList.item(0),
			'list'
		);
	}
};

force_search = (elem) => {
	var search_box = document.getElementsByTagName('button')[0].parentElement.children[0];
	loadContent(
		search_box,
		document.getElementsByClassName('selected')[0].classList.item(0),
		'search'
	);
}

rescanFolder = (elem) => {
	xhr = new XMLHttpRequest();
	xhr.onreadystatechange = () => {
		console.log(xhr.responseText);
	}
	xhr.open('POST',`rescan_dir/${elem.innerHTML.toLowerCase()}`,true);
	xhr.send(null);
}

collapseContent = (elem) => {
	var parent = elem.parentElement;
	var content = parent.children[1];
	content.innerHTML = "";
	elem.classList.remove('expanded');
}

expandVideo = (type) => {
	elem = event.target;
	var parent = elem.parentElement;
	var content = parent.children[1];

	if(elem.classList.contains('expanded') ){
		collapseContent(elem);
	} else {
        var old_elems = document.getElementsByClassName('expanded');
        for(var i = 0; i < old_elems.length; i++){
            collapseContent(old_elems[i]);
        }
        var vid = document.createElement("video");
        if (type == 'movies') {
	        vid.src = `download/movies/${elem.id}`;
        } else {
        	let season = elem.parentElement.parentElement.children[0].innerText;
        	let series = elem.parentElement.parentElement.parentElement.children[0].innerText;
        	vid.src = `download/tv/${series}/${season}/${elem.id}`;
        }
        vid.controls = "true";
		content.appendChild(vid);
        elem.classList.add('expanded');
    }
}

toggleItem = () => {
	elem = event.target;
	var parent = elem.parentElement;
	var content = parent.children;

	if (elem.classList.contains('show')){
		for(var i = 1; i < content.length; i++){
			content[i].style.display = 'none';
		}
		elem.classList.remove('show');
		elem.classList.add('hide');

	} else if (elem.classList.contains('hide')){
		for(var i = 1; i < content.length; i++){
			content[i].style.display = 'block';
		}
		elem.classList.remove('hide');
		elem.classList.add('show');
	}
}

loadContent = (elem,category,mode) => {
	// console.log(category,mode);
	xhr = new XMLHttpRequest();
	xhr.onreadystatechange = () => {
		if(xhr.responseText) {
			results.innerHTML = "";
			try {
				var data = JSON.parse(xhr.responseText);
			} catch(e) {
				console.log(e);
			}
			// data = JSON.parse(xhr.responseText);
			if (category == 'movies') {
				for (var key in data) {
					var item = document.createElement('div');
					item.className = "item"

					header = document.createElement('div');
					header.className = 'header';
					header.id = data[key]['file'];
					header.addEventListener('click',() => {<commit_msg>added more error logging for JSON parsing<commit_after>window.onload = () => {
	loadContent(
		document.getElementsByClassName('selected'),
		'movies',
		'list'	
	)
};

bodyonload = () => {	

};

search = (elem) => {
	if (elem.value.length >= 3){
		loadContent(
			elem,
			document.getElementsByClassName('selected')[0].classList.item(0),
			'search'
		);
	} else {
		loadContent(
			elem,
			document.getElementsByClassName('selected')[0].classList.item(0),
			'list'
		);
	}
};

force_search = (elem) => {
	var search_box = document.getElementsByTagName('button')[0].parentElement.children[0];
	loadContent(
		search_box,
		document.getElementsByClassName('selected')[0].classList.item(0),
		'search'
	);
}

rescanFolder = (elem) => {
	xhr = new XMLHttpRequest();
	xhr.onreadystatechange = () => {
		console.log(xhr.responseText);
	}
	xhr.open('POST',`rescan_dir/${elem.innerHTML.toLowerCase()}`,true);
	xhr.send(null);
}

collapseContent = (elem) => {
	var parent = elem.parentElement;
	var content = parent.children[1];
	content.innerHTML = "";
	elem.classList.remove('expanded');
}

expandVideo = (type) => {
	elem = event.target;
	var parent = elem.parentElement;
	var content = parent.children[1];

	if(elem.classList.contains('expanded') ){
		collapseContent(elem);
	} else {
        var old_elems = document.getElementsByClassName('expanded');
        for(var i = 0; i < old_elems.length; i++){
            collapseContent(old_elems[i]);
        }
        var vid = document.createElement("video");
        if (type == 'movies') {
	        vid.src = `download/movies/${elem.id}`;
        } else {
        	let season = elem.parentElement.parentElement.children[0].innerText;
        	let series = elem.parentElement.parentElement.parentElement.children[0].innerText;
        	vid.src = `download/tv/${series}/${season}/${elem.id}`;
        }
        vid.controls = "true";
		content.appendChild(vid);
        elem.classList.add('expanded');
    }
}

toggleItem = () => {
	elem = event.target;
	var parent = elem.parentElement;
	var content = parent.children;

	if (elem.classList.contains('show')){
		for(var i = 1; i < content.length; i++){
			content[i].style.display = 'none';
		}
		elem.classList.remove('show');
		elem.classList.add('hide');

	} else if (elem.classList.contains('hide')){
		for(var i = 1; i < content.length; i++){
			content[i].style.display = 'block';
		}
		elem.classList.remove('hide');
		elem.classList.add('show');
	}
}

loadContent = (elem,category,mode) => {
	// console.log(category,mode);
	xhr = new XMLHttpRequest();
	xhr.onreadystatechange = () => {
		if(xhr.responseText) {
			results.innerHTML = "";
			try {
				var data = JSON.parse(xhr.responseText);
			} catch(e) {
				console.log("Error", e.stack);
			    console.log("Error", e.name);
			    console.log("Error", e.message);
			}
			// data = JSON.parse(xhr.responseText);
			if (category == 'movies') {
				for (var key in data) {
					var item = document.createElement('div');
					item.className = "item"

					header = document.createElement('div');
					header.className = 'header';
					header.id = data[key]['file'];
					header.addEventListener('click',() => {
{'fraction_non_alphanumeric': 0.1790421086467374, 'fraction_numerical': 0.005143040822886531, 'mean_word_length': 3.4866618601297765, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '952113', 'n_tokens_mistral': 2276, 'n_tokens_neox': 2120, 'n_words': 337}