<commit_before>/**
 * "OtakuTomo"
 * Copyright © 2013 <NAME>
 * <EMAIL>
 * 
 * This program is licensed under the "MIT License"
 * Please see the file COPYING in the source distribution of this software for license terms.
 *
 * popup.js
 * TODO details on this class
 */

function processResults(resp){	
	var htmlHead = "<head><title>OtakuTomo Search Results</title></head>";
	
	var nodes = resp.getElementsByTagName("title");
	var results = "";
	for(var i=0; i < nodes.length; i++){
		results += nodes[i].childNodes[0].nodeValue + "<br>";
	}
	var htmlBody = "<body>" + results + "</body>";
	
	var htmlCode = "<html>" + htmlHead + htmlBody + "</html>";
	var url = "data:text/html," + encodeURIComponent(htmlCode);
	
	chrome.tabs.create({url: url});
	
	//chrome.tabs.create({url: chrome.extension.getURL('results.html')});
	//var pics = root.getElementsByTagName("image");
	//chrome.tabs.create({url: 'http://cdn.myanimelist.net/images/anime/6/7632.jpg'});
}

function getResults(searchURL){
	//chrome.tabs.create({url: searchURL});

	var request = new XMLHttpRequest();
	if (request == null){
        processResults("Unable to create request");
    }
	else{
		request.open("GET", searchURL, true);
		
		request.onreadystatechange = function(){
			if(request.readyState == 4){
				if(request.status == 0){
					processResults("Sorry, request status came back as zero :(");
				}
				if(request.status == 200){
					processResults(request.responseXML);
				}
				if(request.status == 204){
					processResults("No results found");
				}
			}
		};
		
		request.overrideMimeType("text/xml");
        request.send();
	}
}

function submitHandler(event){
	var query = document.getElementById("textbox").value;
	getResults("http://myanimelist.net/api/anime/search.xml?q=" + query);
	event.preventDefault();
}
<commit_msg>Generates page with titles, images, and links to respective info pages on MAL.  Some anime searches result in no response.  Separated out HTML generation from XML processing, but still not behaving as expected; will need to troubleshoot<commit_after>/**
 * "OtakuTomo"
 * Copyright © 2013 <NAME>
 * <EMAIL>
 * 
 * This program is licensed under the "MIT License"
 * Please see the file COPYING in the source distribution of this software for license terms.
 *
 * popup.js
 * TODO details on this class
 */

function displayResults(results){	
	var htmlHead = "<head><title>OtakuTomo Search Results</title></head>";
	var htmlBody = "<body>" + results + "</body>";
	
	var htmlCode = "<html>" + htmlHead + htmlBody + "</html>";
	var url = "data:text/html," + encodeURIComponent(htmlCode);
	
	chrome.tabs.create({url: url});
}

function processResults(resp){	
	var nodes = resp.getElementsByTagName("entry");
	var results = "";
	for(var i=0; i < nodes.length; i++){
		var title = nodes[i].getElementsByTagName("title")[0].childNodes[0].nodeValue;
		var imgurl = nodes[i].getElementsByTagName("image")[0].childNodes[0].nodeValue;
		var id = nodes[i].getElementsByTagName("id")[0].childNodes[0].nodeValue;
		
		results += "\n<div><b>" + title + "</b></div>";
		results += '\n<a href=\'http://myanimelist.net/anime/' + id + '\'><img src=\'' + imgurl + '\'/></a>';
		results += "<br><br>";
	}
	
	displayResults(results);
}

function getResults(searchURL){
	//chrome.tabs.create({url: searchURL});

	var request = new XMLHttpRequest();
	if (request == null){
        processResults("Unable to create request");
    }
	else{
		request.open("GET", searchURL, true);
		
		request.onreadystatechange = function(){
			if(request.readyState == 4){
				if(request.status == 0){
					displayResults("Sorry, request status came back as zero :(");
				}
				if(request.status == 200){
					processResults(request.responseXML);
				}
				if(request.status == 204){
					displayResults("No results found");
				}
			}
		};
		
		request.overrideMimeType("text/xml");
        request.send();
	}
}

function submitHandler(event){
	var query = document.getElementById("textbox").value;
	getResults("http://myanimelist.net/api/anime/search.xml?q=" + query);
	event.preventDefault();
}

{'fraction_non_alphanumeric': 0.16723968565815325, 'fraction_numerical': 0.009332023575638507, 'mean_word_length': 4.047087980173482, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '150986', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1271, 'n_words': 312}