<commit_before>/*! MIT License | github.com/kingalfred/canvas */

/*
 * Replace title
 */
if (document.title === 'Log in to canvas') {
  document.title = 'King Alfred School Canvas';
}

/*
 * Add "Check Homework button"
 */
if (window.location.href.indexOf('courses')) {
  var text = 'Calendar';
  var course = window.location.pathname.split('/')[2];

  $('#section-tabs').append(
    `<li class="section">
      <a class="settings" href="/calendar?include_contexts=course_${course}">
        ${text}
      </a>
    </li>`
  );
}

/*
 * Parent's multiple children
 */
function addChooseChild() {
  
  $.ajax({
    method: 'get',
    url: '/api/v1/users/self/observees?per_page=50',
    dataType: 'json'
  }).then(children => {
    var p = [];
    for (let child of children) {
      p.push(new Promise(function(resolve, reject) {
        $.ajax({
          method: 'get',
          url: '/api/v1/users/' + child.id + '/courses?per_page=20',
          dataType: 'json'
        }).then(courses => {
          var listCourses = [];
          for (let course of courses) {
            listCourses.push('course_' + course.id)
          }
          resolve({
            name: child.name,
            courses: listCourses
          });
        }).fail(err => {
          reject(err);
        });
      }));
    }
    Promise.all(p).then(res => {
      $('#calendar_header').append(`
        <select id="calendar_children" onchange="location = this.value;">
          <option class="calendar_child">Select Child</option><commit_msg>Only get current term's courses<commit_after>/*! MIT License | github.com/kingalfred/canvas */

/*
 * Replace title
 */
if (document.title === 'Log in to canvas') {
  document.title = 'King Alfred School Canvas';
}

/*
 * Add "Check Homework button"
 */
if (window.location.href.indexOf('courses')) {
  var text = 'Calendar';
  var course = window.location.pathname.split('/')[2];

  $('#section-tabs').append(
    `<li class="section">
      <a class="settings" href="/calendar?include_contexts=course_${course}">
        ${text}
      </a>
    </li>`
  );
}

/*
 * Parent's multiple children
 */
function addChooseChild() {
  
  $.ajax({
    method: 'get',
    url: '/api/v1/users/self/observees?per_page=50',
    dataType: 'json'
  }).then(children => {
    var p = [];
    for (let child of children) {
      p.push(new Promise(function(resolve, reject) {
        $.ajax({
          method: 'get',
          url: '/api/v1/users/' + child.id + '/courses?per_page=50&include[]=term',
          dataType: 'json'
        }).then(courses => {
          var listCourses = [];
          for (let course of courses) {
            if ( course.term &&
                 course.term.name.includes( (new Date()).getFullYear() ) 
                ) {
              listCourses.push('course_' + course.id) 
            }
          }
          resolve({
            name: child.name,
            courses: listCourses
          });
        }).fail(err => {
          reject(err);
        });
      }));
    }
    Promise.all(p).then(res => {
      $('#calendar_header').append(`
        <select id="calendar_children" onchange="location = this.value;">
          <option class="calendar_child">Select Child</option>
{'fraction_non_alphanumeric': 0.1754494730316181, 'fraction_numerical': 0.0043397396156230625, 'mean_word_length': 2.1761811023622046, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 25, 'https://': 0, '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': '1488077', 'n_tokens_mistral': 1014, 'n_tokens_neox': 999, 'n_words': 200}