<commit_before>/*
 * biggerthanoptimus
 * by <NAME> <<EMAIL>>
 * see LICENSE for details
 */
(function($){
	$(document).ready(function(){

	});
})(jQuery);<commit_msg>first pass at getting article wordcounts<commit_after>/*
 * biggerthanoptimus
 * by <NAME> <<EMAIL>>
 * see LICENSE for details
 */
(function($){
	var API_URL = 'https://en.wikipedia.org/w/api.php';
	
	function parseArticle(data){
		return {
			title: data.parse.title,
			wordcount: evaluateArticle(data.parse.text['*'])
		};
	}
	
	function evaluateArticle(html){
		var wordcount = 0;
		$(html).find('p').each(function(p){
			var code = $(p).html();
			var words = code.replace(/(<([^>]+)>)/ig,"").split(' ');
			wordcount = wordcount + words.length;
		});
		return wordcount;
	}
	
	function getArticle(query, callback){
		var url = API_URL + '?action=parse&page=' + encodeURIComponent(query) + '&format=json';
		$.ajax(url, {
			dataType: 'jsonp',
			success: function(data, textStatus, jqXHR){
				displayWinner(parseArticle(data));
			},
			error: function(jqXHR, textStatus, errorThrown){
				displayWinner(textStatus);
			}
		});
	}
	
	function displayWinner(article){
		$('#result-box').html(article);
	}
	
	$(document).ready(function(){
		$('form').submit(function(){
			var champion = $('#champion').val();
			var challenger = $('#challenger').val();
			
			getArticle(champion, function(champion){
				getArticle(challenger, function(challenger){
					if(champion.wordcount > challenger.wordcount){
						displayWinner(champion);
					}
					else if(champion.wordcount > challenger.wordcount){
						displayWinner(challenger);
					}
					else{
						alert('unbelievable: a tie.');
					}
				});
			});
			
			return false;
		});
	});
})(jQuery);
{'fraction_non_alphanumeric': 0.18619489559164734, 'fraction_numerical': 0.000580046403712297, 'mean_word_length': 3.859154929577465, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 13, 'https://': 1, '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': '7414231', 'n_tokens_mistral': 693, 'n_tokens_neox': 580, 'n_words': 104}