/*
 * 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() {

  // Add initial option selector
  $('#calendar_header').append(
    `
    <select id="calendar_children" onchange="location = this.value;">
      <option class="calendar_child">Select Option</option>
      <option class="calendar_child" value="/calendar">All Children</option>
    </select>
    `
  );

  // Get user's children
  $.ajax({
    method: 'get',
    url: 'api/v1/users/self/observees?per_page=50',
    dataType: 'json'
  }).then(children => {
    if (children.length < 1) {
      $('#calendar_children').remove();
    }

    var counter = 2;
    // Each child...
    for (var child of children) {
      // Add child option
      $('#calendar_children').append(
        `
        <option class="calendar_child">${child.name}</option>
        `
      );
      // Get courses of that child
      $.ajax({
        method: 'get',
        url: '/api/v1/users/' + child.id + '/courses?per_page=20',
        dataType: 'json'
      }).then(courses => {
        // Create the calendar link
        var courseLinks = '/calendar?include_contexts=';

        // Add every course ID to the link
        for (var course of courses) {
          courseLinks += `course_${course.id},`;
        }

        // Add child option
        $('.calendar_child').eq(counter).attr('value', courseLinks);
        counter++;
      }).fail(err => {
        throw err;
      });
    }
  }).fail(err => {
    throw err;
  });
})();

/*
 * Change favicon of beta environment to green icon
 */

function change_favicon(img) {
    var favicon = document.querySelector('link[rel="shortcut icon"]');
    
    if (!favicon) {
        favicon = document.createElement('link');
        favicon.setAttribute('rel', 'shortcut icon');
        var head = document.querySelector('head');
        head.appendChild(favicon);
    }
    
    
    favicon.setAttribute('type', 'image/png');
    favicon.setAttribute('href', img);
}

change_favicon('https://i.imgur.com/DpAI7L4.png');

@@ -1982,17 +1982,16 @@
 con%0A */%0A
-%0A
 function
@@ -2013,18 +2013,16 @@
 (img) %7B%0A
-  
   var fa
@@ -2029,38 +2029,17 @@
 vicon = 
-document.querySelector
+$
 ('link%5Br
@@ -2061,23 +2061,16 @@
 on%22%5D');%0A
-    %0A  
   if (!f
@@ -2081,240 +2081,70 @@
 on) 
-%7B%0A        favicon = document.createElement
+$('head').append
 ('
+%3C
 link
-');%0A        favicon.setAttribute('rel', 'shortcut icon');%0A        var head = document.querySelector('head');%0A        head.appendChild(favicon);%0A    %7D%0A    %0A    %0A    favicon.setAttribute
+ rel=%22shortcut icon%22%3E');%0A  favicon.attr
 ('ty
@@ -2162,18 +2162,16 @@
 /png');%0A
-  
   favico
@@ -2176,20 +2176,12 @@
 con.
-setAttribute
+attr
 ('hr

Fix favicon function