-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
executable file
·474 lines (433 loc) · 20.2 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/bootstrap-theme.min.css">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/minishare.css">
<link rel="icon" type="image/png" href="img/icon-small.png">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="og:title" content="Course 2 Calendar" />
<meta property="og:description" content="Simply convert your UofG course schedule to a calendar file. Import this file into the calendar application of your choosing." />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://jhvisser.com/course/" />
<meta property="og:image" content="https://jhvisser.com/course/img/icon-large.png" />
<title>Course 2 Calendar</title>
</head>
<body>
<script src="https://cdn.trackjs.com/agent/v3/latest/t.js"></script>
<script>
window.TrackJS && TrackJS.install({
token: "e5f9f43c4b644dbfbe86f40909746e5d"
});
</script>
<!-- Load Facebook SDK for JavaScript -->
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = 'https://connect.facebook.net/en_US/sdk/xfbml.customerchat.js#xfbml=1&version=v2.12&autoLogAppEvents=1';
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<!-- Your customer chat code -->
<div class="fb-customerchat"
attribution=setup_tool
page_id="1031070443612285"
logged_in_greeting="Hi! If you have any issues or comments feel free to start up a chat!"
logged_out_greeting="Hi! If you have any issues or comments feel free to start up a chat!">
</div>
<div class="inner-body container">
<h1 class="banner"><span id="banner-img"></span>Course 2 Calendar for UofG</h1>
<p>Copy your whole web advisor course display page and then paste it into the box below. To do this go to
your WebAdvisor schedule page (not the Class Schedule Grid) and hit CTRL+A and then CTRL+C. This will copy your whole
page and copy it. Now paste it into the box below.</p>
<div style="display:none" class="hiddenVideo">
<video id="howtoVideo" width="1056" height="596" controls loop>
<source src="video/howto.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
<div style="display:none" id="parseWarn" class="alert alert-warning" role="alert">
<ul style="margin-bottom:10px" class="warnMessages list-group list-group-flush">
</ul>
If you're having problems feel free to send an email, use the chat support, or checkout our
<a href="https://www.facebook.com/course2calendar/">Facebook page</a> for support!
</div>
<div style="display:none" class="errorParse alert alert-danger" role="alert">
<b>Oh no!</b> There was a problem processing your data.
If you're having problems feel free to send an email, use the chat support, or checkout our
<a href="https://www.facebook.com/course2calendar/">Facebook page</a> for support!
</div>
<div class="pasteArea">
<textarea name="coursePasteContent" id="coursePasteContent" cols="50" rows="10"></textarea></br>
<div class="stuck-box">
<p>Confused by the instructions? Click the button below to watch a short video.</p>
<button class="btn btn-info btn-sm" id="showVideo">Show Video</button>
</div>
</div>
<button id="getIcal" class="btn btn-primary getIcalButton">Generate Calendar</button>
<div style="display:none" class="resultContent">
<h2>Download and Export Options</h2>
<button class="btn btn-success downloadIcal" id="downloadIcal">Download .ics File</button>
<br>
<p>The .ics file can be imported to any calendar application you may use.</p>
<p>Here are some links demonstrating how to import .ics files into varios popular calendar applications: <br>
<a target="_blank" href="https://support.google.com/calendar/answer/37118?hl=en">Google Calendar</a><br>
<a target="_blank" href="http://help.unc.edu/help/how-to-import-an-icalendar-ics-file-to-outlook/">Outlook</a><br>
<a target="_blank" href="http://smallbusiness.chron.com/import-ics-ical-52066.html">iCal (Mac)</a>
</p>
<i>Please verify exported calendar is accurate. I take no responsibility for any missed classes or exams.</i>
</div>
<footer>
<hr>
Having problems? <a href="mailto:[email protected]">Send me an email</a> or <a href="https://m.me/course2calendar">connect by chat</a><br>
Made by <a href="https://jhvisser.com">Justin Visser</a><br>
Project code is on <a href="https://github.com/Fogest/Course2iCal">GitHub</a><br>
Thank you to <a href="https://trackjs.com">TrackJS</a> for sponsoring our error reporting!
</footer>
</div>
</body>
<script src="js/jquery-1.11.3.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/minishare-0.0.1.js"></script>
<script src="js/Blob.js"></script>
<script src="js/FileSaver.min.js"></script>
<script type="text/javascript">
/**
* ------------------------------------------------
* Functions
* ------------------------------------------------
*/
/**
* Gets the matches given a regex string.
* string - Content you're searching
* regex - Regex search string
* index - Which capture group to use
*/
function getMatches(string, regex, index) {
index || (index = 1); // default to the first capturing group
var matches = [];
var match;
while (match = regex.exec(string)) {
matches.push(match[index]);
}
return matches;
}
function getTermData() {
return $.parseJSON(`{"W15": {"termEnd": "20150403T000000"},"F14":{"termEnd":"20141129T000000"},"S15":{"termEnd":
"20150801T000000"},"F15":{"termEnd": "20151205T000000"},"W16":{"termEnd": "20160409T000000"},
"S16":{"termEnd": "20160804T000000"}, "F16": {"termEnd":"20161201T000000"}, "W17":{"termEnd":
"20170408T000000"}, "S17":{"termEnd": "20170804T000000"},"F17":{"termEnd":"20171201T000000"},
"W18":{"termEnd":"20180406T000000"}, "S18":{"termEnd":"20180901T000000"},
"F18":{"termEnd":"20181205T000000"}, "W19":{"termEnd":"20190406T000000"},
"S19":{"termEnd":"20190803T000000"}, "F19":{"termEnd":"20191130T000000"},
"W20":{"termEnd":"20200404T000000"}, "F20":{"termEnd":"20201203T000000"},
"W21":{"termEnd":"20210412T000000"}, "S21":{"termEnd":"20210803T000000"}}`);
}
function getTerm(content) {
var term = /^(Summer|Fall|Winter)\s\d{4}$/gm.exec(content);
term = term[0];
term = term.split(" ");
term = term[0].charAt(0).toUpperCase() + term[1].charAt(2) + term[1].charAt(3);
var termData = getTermData();
return termData[term];
}
function getAbrv() {
return $.parseJSON('{"AC":"Athletic Centre","ANCC":"OVC Animal Cancer Centre","ANNU":"Animal Science","BWH":"Blackwood Hall","CAF":"Central Animal Facility","CRB":"OVC Clinical Research","CRSC":"Crop Science","DH":"Day Hall","EBA":"Environmental Biology Annex 1","ECBA":"Edmund C. Bovey Building","FS":"Food Science","GRHM":"Graham Hall","HUTT":"H.L. Hutt Building","JHNH":"Johnston Hall","JTP":"John T. Powell Building","LA":"Landscape Architecture","LABL":"lab Animal Building","MAC":"Macdonald Hall","MACN":"MacNaughton","MACS":"Macdonald Stewart Hall","MASS":"Massey Hall","MCKN":"MacKinnon","MCLN":"J.D. Maclachlan","MINS":"Macdonald Institute","MLIB":"Mclaughlin Library","MSAC":"Macdonald Stewart Art Centre","OVCM":"Ontario Veterinary College","REYN":"Reynolds Building","RICH":"Richards Building","ROZH":"Rozanski Hall","SSC":"Science Complex","THRN":"A.A. Thornbrough Building","VSER":"Vehicle Services","WMEM":"War Memorial Hall","ZAV":"Zavitz Hall","ZOOB":"Zoology Annex 2"}');
}
function getFullBuildingName(shortForm) {
var abrv = getAbrv();
abrv = abrv[shortForm];
if(typeof abrv === 'undefined')
return shortForm;
return abrv;
}
function getDateVal(input) {
var otherVal = 0;
switch (input) {
case 'Mon':
otherVal = 1;
break;
case 'Tues':
otherVal = 2;
break;
case 'Wed':
otherVal = 3;
break;
case 'Thur':
otherVal = 4;
break;
case 'Fri':
otherVal = 5;
break;
case 'Sat':
otherVal = 6;
break;
case 'Sun':
otherVal = 0;
break;
default:
otherVal = 0;
}
return otherVal;
}
function convertArrayOfDatesToICSFormat(date) {
var results = [];
for (var i = 0; i < date.length; ++i) {
switch (date[i]) {
case 'Mon':
results.push('MO');
break;
case 'Tues':
results.push('TU');
break;
case 'Wed':
results.push('WE');
break;
case 'Thur':
results.push('TH');
break;
case 'Fri':
results.push('FR');
break;
case 'Sat':
results.push('SA');
break;
case 'Sun':
results.push('SU');
break;
default:
results.push('INVALID');
}
}
return results.join();
}
function getArrayOfDates(date) {
return date.replace(/\s/g, "").split(",");
}
function getCourseLocation(string) {
var location = string.split(",")[0];
var room = string.split(",")[1];
if(typeof room === 'undefined'){
return getFullBuildingName(location) + " (" + location + ")";}
return getFullBuildingName(location) + " (" + location + ")" + '\,' + room;
}
//Course functions
function getCourseTime(string, startOrEnd, type) {
if(string == "Times TBA")
return "";
if(type == "EXAM") {
string = string.substring(0, string.lastIndexOf(" "));
}
var re = /^((?:0[1-9]|1[012]):[0-5][0-9][AP]M) - ((?:0[1-9]|1[012]):[0-5][0-9][AP]M)$/;
var match = re.exec(string);
if (startOrEnd == 'start') {
return match[1];
} else if (startOrEnd == 'end') {
return match[2];
}
}
function getStartDate(course) {
//WebAdvisor says 15 instead of 2015 so add the '20' (really WA???).
return '20' + course[course.length-1];
}
function correctStartTime(courseStart, courseTime, courseDays) {
var re = /\B(AM|PM)/gm;
var subst = ' $1';
var fullDate = courseStart + ' ' + courseTime;
var originalDate = new Date(fullDate.replace(re, subst));
var date = new Date(courseStart);
var sameDay = false;
var dates = getArrayOfDates(courseDays);
for (var i = 0; i < dates.length; ++i) {
if (getDateVal(dates[i]) == date.getDay()) {
sameDay = true;
break;
}
}
if (sameDay == false) {
while (getDateVal(dates[0]) != date.getDay()) {
date.setDate(date.getDate() + 1);
}
}
var pre = date.getFullYear().toString() + ((date.getMonth() + 1) < 10 ? "0" + (date.getMonth() + 1).toString() : (date.getMonth() + 1).toString());
pre += (date.getDate() < 10 ? "0" + date.getDate().toString() : date.getDate().toString());
var post = originalDate.getHours() < 10 ? ("0" + originalDate.getHours().toString()) : (originalDate.getHours().toString());
if(originalDate.getMinutes() == 0)
post += "0000";
else {
post += originalDate.getMinutes() < 10 ? ("0" + originalDate.getMinutes().toString()) : (originalDate.getMinutes().toString() + "00");
}
return pre + "T" + post;
}
function correctEndTime(courseStart, courseTime, courseDays) {
var re = /\B(AM|PM)/gm;
var subst = ' $1';
var fullDate = courseStart + ' ' + courseTime;
var originalDate = new Date(fullDate.replace(re, subst));
var date = new Date(courseStart);
var sameDay = false;
var dates = getArrayOfDates(courseDays);
for (var i = 0; i < dates.length; ++i) {
if (getDateVal(dates[i]) == date.getDay()) {
sameDay = true;
break;
}
}
if (sameDay == false) {
while (getDateVal(dates[0]) != date.getDay()) {
date.setDate(date.getDate() + 1);
}
}
var pre = date.getFullYear().toString() + ((date.getMonth() + 1) < 10 ? "0" + (date.getMonth() + 1).toString() : (date.getMonth() + 1).toString());
pre += (date.getDate() < 10 ? "0" + date.getDate().toString() : date.getDate().toString());
var post = originalDate.getHours() < 10 ? ("0" + originalDate.getHours().toString()) : (originalDate.getHours().toString());
if(originalDate.getMinutes() == 0)
post += "0000";
else {
post += originalDate.getMinutes() < 10 ? ("0" + originalDate.getMinutes().toString()) : (originalDate.getMinutes().toString() + "00");
}
return pre + "T" + post;
}
function getDays(string) {
return string.substr(string.indexOf(" ") + 1);
}
function getCourseType(string) {
return string.substr(0, string.indexOf(" "));
}
function getExamStartDate(string) {
string = string.split(" ");
string = string[string.length - 1];
string = string.replace('(', '').replace(')', '');
return string;
}
/**
* Parses user pasted content finding the courses within it
*/
function parsePasteContent(content) {
//Get courses in array.
content = content.replace(/^[Pp]$/gm,"");
content = content.replace(/^\s*[\r\n]/gm, "");
var courses = getMatches(content, /(\w{3,4}(\*(\d+|DE)){2}[\s\S]*?\D\d{1,2}\/\d{1,2}\/\d{1,2})+/gm, 1);
if(!content) {
alert("There was an error. Did you enter data?");
return false;
}
var term = getTerm(content);
var ical = 'BEGIN:VCALENDAR\n';
ical += 'VERSION:2.0\n';
ical += 'PRODID:-//Justin Visser/jhvisser.com//iCal Export v1.0//EN\n';
for (var i = 0; i < courses.length; i++) {
var splitCourse = courses[i].split("\n");
var startDate = getStartDate(splitCourse);
var courseCode = splitCourse[0];
for (var j = 2; j < (splitCourse.length-2); j = j + 3) {
//Start at index 2 as that is when classes section starts.
//Subtract 2 from length as the last two entries are the credit total and start date.
//j+3 as each class info is in lines of 3.
if(getCourseType(splitCourse[j]) == 'Distance')
continue;
ical += 'BEGIN:VEVENT\n';
if(getCourseType(splitCourse[j]) == "EXAM") {
ical += 'DTSTART:' + correctStartTime(getExamStartDate(splitCourse[j + 1]), getCourseTime(splitCourse[j + 1], 'start', getCourseType(splitCourse[j])), getDays(splitCourse[j])) + '\n';
ical += 'DTEND:' + correctEndTime(getExamStartDate(splitCourse[j + 1]), getCourseTime(splitCourse[j + 1], 'end', getCourseType(splitCourse[j])), getDays(splitCourse[j])) + '\n';
} else {
ical += 'DTSTART:' + correctStartTime(startDate, getCourseTime(splitCourse[j + 1], 'start', getCourseType(splitCourse[j])), getDays(splitCourse[j])) + '\n';
ical += 'DTEND:' + correctEndTime(startDate, getCourseTime(splitCourse[j + 1], 'end', getCourseType(splitCourse[j])), getDays(splitCourse[j])) + '\n';
}
if(getCourseType(splitCourse[j]) != "EXAM") {
ical += 'RRULE:FREQ=WEEKLY;UNTIL='+ term.termEnd +';WKST=SU';
var dates = getArrayOfDates(getDays(splitCourse[j]));
var icsDates = convertArrayOfDatesToICSFormat(dates);
if (!icsDates.includes("INVALID"))
ical += ';BYDAY=' + icsDates;
else {
var invalidDay = dates.includes('DaysTBA') ? '"Days TBA" set as the day it occurs' : 'an invalid day';
var warnMsg = 'Your course "' + courseCode + '" has ' + invalidDay + '. This entry may show up on your calendar in an undesired manner, and will require manual adjustment.';
addWarningMessage(warnMsg);
$("#parseWarn").show();
}
ical += '\n'
}
ical += 'SUMMARY:' + '(' + getCourseType(splitCourse[j]) + ') ' + courseCode + '\n';
ical += 'LOCATION:' + getCourseLocation(splitCourse[j+2]) + ', University of Guelph\n';
ical += 'DESCRIPTION:' + courseCode + '\n';
ical += 'END:VEVENT\n';
}
}
ical += 'END:VCALENDAR';
var download = new Blob([ical], {
type: 'text/calendar'
});
$("#downloadIcal").data('download', download);
return true;
}
function logRequest(content) {
//Log the request to be used for resolving debugging problems.
$.ajax({
method: "POST",
url: "log.php",
data: {data: content}
});
}
function addWarningMessage(msg) {
$("#parseWarn .warnMessages").append($('<li class="warnMessage list-group-item-warning list-group-item"></li>').text(msg));
}
function clearWarningMessages() {
$("#parseWarn .warnMessages").empty();
}
/**
* ------------------------------------------------
* Event bindings
* ------------------------------------------------
*/
$("#showVideo").click(function(e) {
e.preventDefault();
var buttonText = $(this).text();
var video = document.getElementById("howtoVideo");
if(buttonText == "Show Video") {
$(this).text("Hide Video");
$(".hiddenVideo").slideToggle();
video.play();
} else {
$(this).text("Show Video");
$(".hiddenVideo").slideToggle();
video.currentTime = 0;
video.pause();
}
});
//Called when getIcal button is pressed.
$("#getIcal").click(function(e) {
e.preventDefault();
logRequest($("#coursePasteContent").val())
$(".resultContent").slideUp(300);
clearWarningMessages();
$("#parseWarn").hide();
let status;
try {
status = parsePasteContent($("#coursePasteContent").val());
} catch(err) {
status = false;
}
//Reveal content if success:
if(status) {
$(".errorParse").hide();
$(".resultContent").slideDown(300);
$.miniShare( {
message: "Care to Share?",
twitter_message: "Check out \"Course 2 Calendar\" it allows you to easily export your course schedule.",
url: "https://jhvisser.com/course/"
});
} else {
//Error parsing content, give error:
$(".errorParse").show();
}
});
$("#downloadIcal").click(function(e) {
e.preventDefault();
saveAs($(this).data('download'), "Course Calendar.ics");
});
</script>
</html>