<commit_before>fixDivHeight();
init();
var toggledEvents = [];

function init() {
  var entryInfo = {
      entryPoint: "stupla_fs09",
      rootElementLevel: 4
  }

  var subjects = getElements(getRootElement(entryInfo));

  var d= $('<input type="button" id="downloadICS" style="background: white; border-radius: 5px; font-size: 15px; border: solid #a3a3a3 2px;font-family: Arial;text-decoration: none;padding: 0px 5px 0px 5px;font-family: Arial" value="Download"/> ');
  d.insertBefore(subjects[0]);
  $("#downloadICS").on('click', function(entryInfo){
    if (toggledEvents.length > 0) {
      download(toggledEvents);
    } else {
      alert("Keine Veranstaltungen ausgewählt.")
    };
  });

  var i;
  for (i = 0; i < subjects.length; i++){
    var r= $('<input type="button" class="eventToggle" style="background: white; border-radius: 5px; font-size: 15px;  color: #07d41f; border: solid #a3a3a3 2px;font-family: Arial;text-decoration: none;padding: 0px 5px 0px 5px;font-family: Arial" value="+"/> ');
    r.insertBefore(subjects[i].childNodes[1].childNodes[0]);
  }

  $(".eventToggle").on('click', function(entryInfo){
    toggleEvent(this.parentNode.parentNode);
    console.log(toggledEvents);
  });

}

function download(subjects) {
  var cal = [];

  cal.push('BEGIN:VCALENDAR');
  cal.push('CALSCALE:GREGORIAN');
  cal.push('VERSION:2.0');
  cal.push('METHOD:PUBLISH');
  cal.push('X-WR-CALNAME:Uni');
  cal.push('X-WR-TIMEZONE:Europe/Berlin');
  cal.push('X-APPLE-CALENDAR-COLOR:#1BADF8');
  cal.push('BEGIN:VTIMEZONE');
  cal.push('TZID:Europe/Berlin');
  cal.push('BEGIN:DAYLIGHT');
  cal.push('TZOFFSETFROM:+0100');
  cal.push('RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU');
  cal.push('DTSTART:19810329T020000');
  cal.push('TZNAME:MESZ');
  cal.push('TZOFFSETTO:+0200');
  cal.push('END:DAYLIGHT');
  cal.push('BEGIN:STANDARD');
  cal.push('TZOFFSETFROM:+0200');
  cal.push('RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU');
  cal.push('DTSTART:19961027T030000');
  cal.push('TZNAME:MEZ');
  cal.push('TZOFFSETTO:+0100');
  cal.push('END:STANDARD');
  cal.push('END:VTIMEZONE');

  try {
    for (i in subjects) {
      var event = getEventData(subjects[i]);
      cal = addEvent(cal, event);
    }
  } catch (e) {}

  cal.push('END:VCALENDAR');
  var str = cal.join('\n');

  console.log('Output: ');
  console.log([str]);

  var dl = new Blob([str], {type: "text/plain;charset=utf-8"});
  saveAs(dl, "calendar.ics");
}

function toggleEvent(object) {
  if (!containsObject(object, toggledEvents)) {
    toggledEvents.push(object);
  } else {
    toggledEvents = removeFromList(toggledEvents, getObjectIndex(object, toggledEvents, object));
  }
}

function removeFromList(list, i, object) {
  return list.filter(function (object) {
      return list[i] !== object;
    });
}

function getObjectIndex(object, list) {
  var i;
  for (i = 0; i< list.length; i++) {
    if (list[i] === object) {
      return i;
    }
  }
}

function containsObject(object, list) {
    var i;
    for (i = 0; i < list.length; i++) {
        if (list[i] === object) {
            return true;
        }
    }

    return false;
}

function getRootElement(entryInfo) {
  return $(document.getElementsByClassName(entryInfo.entryPoint)[0]).parents().eq(entryInfo.rootElementLevel)[0];
}

function getElements(root) {
  return root.getElementsByTagName('div');
}

function getNameOfLecture(object) {
    var name = object.childNodes[1].innerText;
    return name.slice(0, (name.length - 12));
}

function getSpeakerOfLecture(object) {<commit_msg>implement downloadAll and usability improvements<commit_after>fixDivHeight();
var toggledEvents = [];

/*
 * checks, if current page is the text one
 */
if (/vers=text/.test(self.location.href)) {
  init();
}

/*
 * initializes the plugin, loads the data, inserts the buttons, etc
 */
function init() {
  var entryInfo = {
      entryPoint: "stupla_fs09",
      rootElementLevel: 4
  }

  var subjects = getElements(getRootElement(entryInfo));

  var downloadSelected= $('<input type="button" id="downloadSelected" style="background: white; border-radius: 5px; font-size: 15px; border: solid #a3a3a3 2px;font-family: Helvetica;text-decoration: none;padding: 0px 7px 0px 7px;font-family: Arial" value="Download selected"/>');
  downloadSelected.insertBefore(subjects[0]);
  $("#downloadSelected").on('click', function(entryInfo){
    if (toggledEvents.length > 0) {
      download(toggledEvents);
    } else {
      alert("Keine Veranstaltungen ausgewählt.")
    };
  });

  var downloadAll= $('<input type="button" id="downloadAll" style="background: white; border-radius: 5px; font-size: 15px; border: solid #a3a3a3 2px;font-family: Helvetica;text-decoration: none;padding: 0px 7px 0px 7px;font-family: Arial" value="Download all"/>');
  downloadAll.insertBefore(subjects[0]);
  $("#downloadAll").on('click', function(entryInfo){
    if (subjects.length > 0) {
      download(subjects);
    } else {
      alert("Keine Veranstaltungen gefunden.")
    };
  });

  var i;
  for (i = 0; i < subjects.length; i++){
    var r= $('<input type="button" class="eventToggle" style="background: white; border-radius: 5px; font-size: 15px;  color: #07d41f; border: solid #a3a3a3 2px;font-family: Arial;text-decoration: none;padding: 0px 7px 0px 7px;font-family: Arial" value="+"/> ');
    r.insertBefore(subjects[i].childNodes[1].childNodes[0]);
  }

  $(".eventToggle").on('click', function(entryInfo){
    var object = this.parentNode.parentNode;
    if (!containsObject(object, toggledEvents)) {
      toggledEvents.push(object);
      this.value = '-';
      this.style.color = 'red'
      object.style.background = '#BEE8BA';
    } else {
      toggledEvents = removeFromList(toggledEvents, getObjectIndex(object, toggledEvents, object));
      this.value = '+';
      this.style.color = '#07d41f';
      object.style.background = 'white';
    }
  });

}

/*
 * downloads the given events. takes an array as argument an concatenates it to a string to build an vCalendar formatted .ics file
 */
function download(subjects) {
  var cal = [];

  cal.push('BEGIN:VCALENDAR');
  cal.push('CALSCALE:GREGORIAN');
  cal.push('VERSION:2.0');
  cal.push('METHOD:PUBLISH');
  cal.push('X-WR-CALNAME:Uni');
  cal.push('X-WR-TIMEZONE:Europe/Berlin');
  cal.push('X-APPLE-CALENDAR-COLOR:#1BADF8');
  cal.push('BEGIN:VTIMEZONE');
  cal.push('TZID:Europe/Berlin');
  cal.push('BEGIN:DAYLIGHT');
  cal.push('TZOFFSETFROM:+0100');
  cal.push('RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU');
  cal.push('DTSTART:19810329T020000');
  cal.push('TZNAME:MESZ');
  cal.push('TZOFFSETTO:+0200');
  cal.push('END:DAYLIGHT');
  cal.push('BEGIN:STANDARD');
  cal.push('TZOFFSETFROM:+0200');
  cal.push('RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU');
  cal.push('DTSTART:19961027T030000');
  cal.push('TZNAME:MEZ');
  cal.push('TZOFFSETTO:+0100');
  cal.push('END:STANDARD');
  cal.push('END:VTIMEZONE');

  try {
    for (i in subjects) {
      var event = getEventData(subjects[i]);
      cal = addEvent(cal, event);
    }
  } catch (e) {}

  cal.push('END:VCALENDAR');
  var str = cal.join('\n');

  console.log('Output: ');
  console.log([str]);

  var dl = new Blob([str], {type: "text/plain;charset=utf-8"});
  saveAs(dl, "calendar.ics");
}

/*
 * removes a given object from a given array. needed for removing an event from selection
 */
function removeFromList(list, i, object) {
  return list.filter(function (object) {
      return list[i] !== object;
    });
}

/*
 * returns the index of an object in an array, needed for removeFromList()
 */
function getObjectIndex(object, list) {
  var i;
  for (i = 0; i< list.length; i++) {
    if (list[i] === object) {
      return i;
    }
  }
}

/*
 * returns whether or not an object is present in an array
 */
function containsObject(object, list) {
    var i;
    for (i = 0; i < list.length; i++) {
        if (list[i] === object) {
            return true;
        }
    }

    return false;
}

/*
 * returns the root element, which is the highest element on the page we work with
 */
function getRootElement(entryInfo) {
  return $(document.getElementsByClassName(entryInfo.entryPoint)[0]).parents().eq(entryInfo.rootElementLevel)[0];
}

/*
 * returns an array of all events present on the page
 */
function getElements(root) {
  return root.getElementsByTagName('div');
}

function getNameOfLecture(object) {
    var name = object.childNodes[1].innerText;
    return name.slice(0, (name.length - 12));
}

function getSpeakerOfLecture(object) {
{'fraction_non_alphanumeric': 0.17192651907677814, 'fraction_numerical': 0.024729156853509186, 'mean_word_length': 4.159781287970838, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '204481', 'n_tokens_mistral': 3170, 'n_tokens_neox': 3005, 'n_words': 588}