<commit_before>{% extends "base.html" %}
{% block content %}<br><br><br><br><br><br><br>

<style type="text/css">

  textarea {
    position: absolute;
    font-size: 20px;
}
#type {
    color: gray;
    background-color: black;
    opacity: .9;
}
#typed {
    background: none;
    z-index: 10;
    color: #00FF00;
}

</style>


<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<SCRIPT LANGUAGE="JavaScript">
$(document).delegate('#typed', 'keydown', function(e) {
  var keyCode = e.keyCode || e.which;

  if (keyCode == 9) {
    e.preventDefault();
    var start = $(this).get(0).selectionStart;
    var end = $(this).get(0).selectionEnd;

    // set textarea value to: text before caret + tab + text after caret
    $(this).val($(this).val().substring(0, start)
                + "\t"
                + $(this).val().substring(end));

    // put caret at right position again
    $(this).get(0).selectionStart =
    $(this).get(0).selectionEnd = start + 1;
  }
});

var hasStarted = false;

//strToTest is an array object that holds various strings to be used as the base typing test
// - If you update the array, be sure to update the intToTestCnt<commit_msg>adding github api to singleplayer<commit_after>{% extends "base.html" %}
{% block content %}<br><br><br><br><br><br><br>

<style type="text/css">

  textarea {
    position: absolute;
    font-size: 20px;
}
#type {
    color: gray;
    background-color: black;
    opacity: .9;
}
#typed {
    background: none;
    z-index: 10;
    color: #00FF00;
}

</style>


<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<SCRIPT LANGUAGE="JavaScript">
var strToTest;
function getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min)) + min;
}
$.ajax({url: 'https://api.github.com/search/repositories?q=language:python+sort:updated'}).done(function(data) {
  var l = data.items.length;
  var i = getRandomInt(0, l - 1);
  var item = data.items[i];
  var repo = item.name;
  var user = item.owner.login;
  $.ajax({url: 'https://api.github.com/search/code?q=language:python+repo:' + item.full_name}).done(function(codeData) {
    var cl = codeData.items.length;
    var ci = getRandomInt(0, cl - 1);
    var citem = codeData.items[ci];
    var path = citem.path;
    $.ajax({
           method : "POST",
            url : "/play/content/",
            data : {"user": user,
                    "repo": repo,
                    "path": path}
        }).done(function(response){
          $('#type').val(response);
          strToTest[0] = response;
          strToTestType = response;
        }).fail(function(){
            alert("fail");
        });
  });
});
var opponent = "{{ opponent }}"
var secs = 0;
$(document).delegate('#typed', 'keyup', function(e) {
  var keyCode = e.keyCode || e.which;
  if (keyCode == 9) {
    e.preventDefault();
    var start = $(this).get(0).selectionStart;
    var end = $(this).get(0).selectionEnd;
    // set textarea value to: text before caret + tab + text after caret
    $(this).val($(this).val().substring(0, start)
                + "\t"
                + $(this).val().substring(end));
    // put caret at right position again
    $(this).get(0).selectionStart =
    $(this).get(0).selectionEnd = start + 1;
  }
  $.ajax({
     method : "POST",
      url : "/play/multi/",
      data : {"user_input": $('#typed').val(),
              "opponent": opponent}
  }).done(function(response){
    $('#typed2').val(response)
  }).fail(function(){
      alert("fail");
  });
});

var hasStarted = false;

//strToTest is an array object that holds various strings to be used as the base typing test
// - If you update the array, be sure to update the intToTestCnt
{'fraction_non_alphanumeric': 0.1810064935064935, 'fraction_numerical': 0.012716450216450216, 'mean_word_length': 2.780163599182004, 'pattern_counts': {'":': 5, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 4, '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': '6432042', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1219, 'n_words': 299}