Last active
October 10, 2016 10:53
-
-
Save AlexVonB/4c30d05d32dc012100ca7fb8018e2921 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var EVENT_NAME = prompt("Kursname eingeben"); | |
var scrpt = document.createElement('script'); | |
scrpt.src='https://rawgit.com/connorbode/ics.js/master/ics.deps.min.js'; | |
scrpt.type = 'text/javascript'; | |
document.head.appendChild(scrpt); | |
var scrpt = document.createElement('script'); | |
scrpt.src='https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.3/FileSaver.min.js'; | |
scrpt.type = 'text/javascript'; | |
document.head.appendChild(scrpt); | |
setTimeout(createIcs, 1000); | |
Date.prototype.stdTimezoneOffset = function () { | |
var jan = new Date(this.getFullYear(), 0, 1); | |
var jul = new Date(this.getFullYear(), 6, 1); | |
return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset()); | |
} | |
Date.prototype.dst = function () { | |
return this.getTimezoneOffset() < this.stdTimezoneOffset(); | |
} | |
function createIcs() { | |
var table = document.getElementsByTagName('tbody') [0]; | |
var cal = ics(); | |
for (var i = 0; i < table.childElementCount; i++) { | |
var row = table.childNodes[i]; | |
var date = row.childNodes[1].textContent.split('.'); | |
var isoDate = date[2] + '-' + date[1] + '-' + date[0]; | |
var diff = ((new Date(isoDate)).dst()) ? -2 : -1; | |
var time = row.childNodes[2].textContent.split('-'); | |
var from = time[0]; | |
var to = time[1]; | |
var fromSplit = from.split(':'); | |
var toSplit = to.split(':'); | |
var isoFrom = isoDate + 'T' + (parseInt(fromSplit[0])+diff) + ':' + fromSplit[1]; | |
var isoTo = isoDate + 'T' + (parseInt(toSplit[0])+diff) + ':' + toSplit[1]; | |
var loc = row.childNodes[3].childNodes[0].textContent; | |
cal.addEvent(EVENT_NAME, '', loc, isoFrom, isoTo); | |
console.log('Am ' + date + ' von ' + isoFrom + ' bis ' + isoTo + ' in ' + loc); | |
} | |
cal.download(EVENT_NAME); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment