Skip to content

Instantly share code, notes, and snippets.

@haampie
Created September 10, 2011 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haampie/1208756 to your computer and use it in GitHub Desktop.
Save haampie/1208756 to your computer and use it in GitHub Desktop.
RUG kalender naar Google Calendar dmv CSV
NodeList.prototype.forEach = Array.prototype.forEach;
HTMLCollection.prototype.forEach = Array.prototype.forEach;
Date.prototype.getSimpleDateString = function(){
return this.getDate() + '-' + (this.getMonth()+1) + '-' + this.getFullYear();
};
function Vakkenlijst(){
this.lijst = [];
}
Vakkenlijst.prototype.push = function(vak){
this.lijst.push(vak);
};
Vakkenlijst.prototype.toCSV = function(){
var csv = "Subject,Start Date,Start Time,End Time,Location\n";
this.lijst.forEach(function(a){
csv += '"' + [a.vak, a.dag, a.van, a.tot, a.locatie].join('","') + '"\n';
});
return csv;
};
function Vak(dag, vanEnTot, locatie, type, vak){
var aVanEnTot = vanEnTot.split('-');
this.dag = dag;
this.locatie = locatie;
this.vak = vak;
this.van = aVanEnTot[0];
this.tot = aVanEnTot[1];
this.voegToe(this, type, kalenders);
}
Vak.prototype.voegToe = function(les, type, kalenderLijst){
for(var i=0; i<kalenderLijst.length; i++){
if(kalenderLijst[i].regex.test(type)){
this.type = i;
kalenderLijst[i].items.push(les);
return;
}
}
};
var kalenders = [
{regex: /hoorcollege/, naam: "RUG Hoorcolleges", items: new Vakkenlijst()},
{regex: /werkcollege/, naam: "RUG Werkcolleges", items: new Vakkenlijst()},
{regex: /prakticum|practicum|practikum/, naam: "RUG Praktica", items: new Vakkenlijst()},
{regex: /toets|tentamen|examen/, naam: "RUG Toetsen", items: new Vakkenlijst()},
{regex: /./, naam: "RUG Algemeen", items: new Vakkenlijst()}
];
var table, rooster = [];
document.querySelectorAll('.tableContainer .userContentTable tbody').forEach(function(elm){
if(elm.children[0].children[1].innerText == 'Dag'){
table = elm;
}
});
var currDate;
table.children.forEach(function(el){
if(el.children.length == 9 && el.children[0].tagName.toLowerCase() == 'td' && el.children[6].innerText.trim().length > 0){
var dateField = el.children[2].innerText.split('-');
if(dateField.length === 3){
splitDate = dateField.map(function(dateEl, i){
var asInt = parseInt(dateEl, 10);
if(i == 1) asInt--;
if(i == 2) asInt += 2000;
return asInt;
});
currDate = new Date(splitDate[2], splitDate[1], splitDate[0]);
}
rooster.push(new Vak(
currDate.getSimpleDateString(),
el.children[3].innerText,
el.children[4].innerText,
el.children[5].innerText,
el.children[6].innerText
));
}
});
for(var i=0; i<kalenders.length; i++){
var asCSV = kalenders[i].items.toCSV(),
title = document.createElement('h2'),
textarea = document.createElement('textarea');
console.group(kalenders[i].naam);
console.log(asCSV);
console.groupEnd();
title.innerHTML = kalenders[i].naam;
textarea.value = asCSV;
textarea.style.width = '100%';
textarea.style.height = '200px';
table.parentNode.parentNode.parentNode.insertBefore(textarea, table.nextSibling);
textarea.parentNode.insertBefore(title, textarea);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment