-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
257 lines (242 loc) · 10.4 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>iCallate</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="alert alert-info visible-xs-block" role="alert">
<strong>Warning!</strong> This tool doesn't work well on mobile devices. Try it on a computer!
</div>
<h1>iCallate</h1>
<p class="lead">Allocate+ to iCalendar tool</p>
<p>
Note: Monash has its own version <a href="https://my.monash.edu.au/news-and-events/calendar-feeds/direct.html">here</a>. To compare this and Monash's version:
<ul>
<li>Benefits
<ul>
<li>Clayton campus: readable room addresses instead of location codes</li>
<li>Calendar has all events this semester, whereas Monash's only gives some events (around 4 weeks)</li>
<li>Can manually change parts of the calendar yourself</li>
</ul>
</li>
<li>Downsides
<ul>
<li>Does not automatically sync with Allocate, or class changes</li>
<li>Could be stealing your info?</li>
</ul>
</ul>
</p>
<h2>Step 1</h2>
<p>Log into <a href="https://www.monash.edu/timetables/allocate/login">Allocate+</a>.</p>
<h2>Step 2</h2>
<p>
Open up the JavaScript console <em>on the Allocate+ page</em>. On most browsers, press <kbd>F12</kbd> and click on something which says "Console".
</p>
<p>
If you are using Chrome, Firefox or Safari, <strong>type in</strong> <code>copy(window.data.student.allocated)</code> exactly as it's written and press <kbd>Enter</kbd>. If you can, you should type it, not copy and paste it. This will copy your Allocate+ allocations to the clipboard. Skip to Step 3.
</p>
<br />
<p>
If you are not using those browsers, copy the block of code below and paste it in. <strong>DO NOT PRESS ENTER</strong>.
</p>
<pre>$(document.body).append(
'<textarea style="width: 100%; height: 300px; z-index: 9999999999; position: fixed;">' +
JSON.stringify(data.student.allocated) +
'</textarea>'
)</pre>
<p>
Stare at the code that you just pasted in. <strong>Make sure it's the same code you copied.</strong> If you believe the code is not malicious, press <kbd>Enter</kbd>.
</p>
<p>
A big bunch of text (representing your Allocate+ allocations) should appear at the top of your screen. Copy it for Step 3.
</p>
<h2>Step 3</h2>
<p>
Paste your Allocate+ allocations into the box below:
<div>
<input type="text" placeholder="data.student.allocated" class="form-control" id="user-input">
</div>
</p>
<h2>Step 4</h2>
<p>
Choose your options:
<div class="checkbox">
<label>
<input type="checkbox" value="" id="clayton-addresses" checked>
Monash Clayton: Use addresses (Room G15, 9 Rainforest Walk) instead of <a href="http://www.monash.edu/timetables/about/codes-abbreviations">location codes</a> (CL_9Rnf/G15)
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" value="" id="description-staff" checked>
Show staff in event descriptions
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" value="" id="description-maplink" checked>
Show link to the official Monash map (example: <a href="http://www.monash.edu/people/maps?Location=CL_9Rnf%2FG15">Room G15, 9 Rainforest Walk</a>) in event descriptions
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" value="" id="campus-display">
Display campus in event titles
</label>
</div>
<br>
Where should the unit name from Allocate+ (example: INTRO TO COMPL MATHS) go?
<div class="radio">
<label>
<input type="radio" name="unit-name-pos" id="unit-name-pos-title" value="title">
In the event title (replaces the unit code)
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="unit-name-pos" id="unit-name-pos-desc" value="desc">
In the event description
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="unit-name-pos" id="unit-name-pos-none" value="none" checked>
Neither
</label>
</div>
</p>
<h2>Step 5</h2>
<p>
<button class="btn btn-default" id="generate-button"><span class="glyphicon glyphicon-calendar"></span> Download <code>.ics</code></button>
</p>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.2/moment.min.js"></script>
<script src="js/Blob.js"></script>
<script src="js/FileSaver.js"></script>
<script>
if (!String.prototype.startsWith) {
String.prototype.startsWith = function(searchString, position){
position = position || 0;
return this.substr(position, searchString.length) === searchString;
};
}
var timezoneInfo = "BEGIN:VTIMEZONE\nTZID:Australia/Melbourne\nX-LIC:Australia/Melbourne\nBEGIN:DAYLIGHT\nTZOFFSETFROM:+1000\nTZOFFSETTO:+1100\nTZNAME:AEDT\nDTSTART:19700308T020000\nRRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=1SU\nEND:DAYLIGHT\nBEGIN:STANDARD\nTZOFFSETFROM:+1100\nTZOFFSETTO:+1000\nTZNAME:AEST\nDTSTART:19701101T020000\nRRULE:FREQ=YEARLY;BYMONTH=4;BYDAY=1SU\nEND:STANDARD\nEND:VTIMEZONE\n";
var claytonStreetNames = {
All: "Alliance Lane",
Anc: "Ancora Imparo Way",
Chn: "Chancellors Walk",
Col: "College Walk",
Exh: "Exhibition Walk",
FGR: "Ferntree Gully Road",
Inn: "Innovation Walk",
Rnf: "Rainforest Walk",
Res: "Research Way",
Sce: "Scenic Boulevard"
};
var locationReplacements = [
[/Exh\w\//, "Exh/"]
]
// http://stackoverflow.com/a/30832210
function download(text, name, type) {
var file = new Blob([text], { type: type });
saveAs(file, name);
}
function dayOfWeektoiCal(dayOfWeek) {
return dayOfWeek.substr(0, 2).toUpperCase();
}
function momentToiCal(m) {
return "TZID=Australia/Melbourne:" + m.format("YYYYMMDDTHHmmss");
}
// Because m is now a date in the "first week of the year", we can just add
// "index" weeks to it.
function momentWeekIndexToIcal(m, index) {
return momentToiCal(moment(m).add(index, "weeks"));
}
function toVevent(obj) {
var summary = "";
switch (document.querySelector("input[name='unit-name-pos']:checked").value) {
case "title":
summary = obj.subject_description;
break;
case "desc":
case "none":
summary = obj.subject_code.substr(0, 7);
break;
}
summary += " " + obj.activityType;
if (document.getElementById("campus-display").checked) {
summary += " (" + obj.campus + ")";
}
var descriptionLines = [];
if (document.getElementById("unit-name-pos-desc").checked) {
descriptionLines.push(obj.subject_description)
}
if (obj.description !== "-") {
descriptionLines.push(obj.description);
}
if (document.getElementById("description-staff").checked && obj.staff !== "-") {
descriptionLines.push("Staff: " + obj.staff);
}
if (document.getElementById("description-maplink").checked && obj.location !== "-") {
descriptionLines.push("Map link: https://www.monash.edu/people/maps?Location=" + encodeURIComponent(obj.location));
}
var description = descriptionLines.join("\\n")
var location = obj.location;
var i = locationReplacements.length; while (i--) {
location = location.replace(locationReplacements[i][0], locationReplacements[i][1]);
}
if (location.startsWith("CL_")) {
const [_, streetCode, streetNumber, buildingName, roomCode] = location.match(/CL_(\w{3})-(\d{1,2})\.(.+)_(.+)/);
if (document.getElementById("clayton-addresses").checked && location.startsWith("CL_") && claytonStreetNames.hasOwnProperty(streetCode)) {
// Escape commas to ensure compatibility with macOS Calendar
location = `Room ${roomCode}\\, ${buildingName}\\, ${streetNumber} ${claytonStreetNames[streetCode]}`;
}
if (obj.location === "-") {
location = "";
}
}
// Need to get year from event!
// Turns out that obj.start_date is "the first Monday of the first week"...
// ...which may be in the year before.
// However, it's consistent with what Allocate does - so let's use that instead.
var eventStartNoWeek = moment(obj.start_date + " " + obj.start_time, "DD/MM/YYYY HH:mm").day(obj.day_of_week);
var eventEndNoWeek = moment(eventStartNoWeek).add(obj.duration, "minutes");
var firstWeekIndex = obj.week_pattern.indexOf("1");
var count = obj.week_pattern.lastIndexOf("1") - firstWeekIndex + 1;
var excludeWeekIndices = [];
// need to search from obj.week_pattern[firstWeekIndex + 1] to obj.week_pattern[firstWeekIndex + count - 2] inclusive for 0s
for (var i = firstWeekIndex + 1; i < firstWeekIndex + count - 1; i++) {
if (obj.week_pattern[i] === "0") {
excludeWeekIndices.push(i);
}
}
var dtStart = momentWeekIndexToIcal(eventStartNoWeek, firstWeekIndex);
var dtEnd = momentWeekIndexToIcal(eventEndNoWeek, firstWeekIndex);
var rRule = "FREQ=WEEKLY;COUNT=" + count + ";BYDAY=" + obj.day_of_week.substr(0, 2).toUpperCase();
var exDateString = excludeWeekIndices.map(function (index) {
return "EXDATE;" + momentWeekIndexToIcal(eventStartNoWeek, index);
}).join("\n");
return "BEGIN:VEVENT\nDTSTART;" + dtStart + "\nDTEND;" + dtEnd + "\nRRULE:" + rRule + "\n" + exDateString + "\nDESCRIPTION:" + description + "\nLOCATION:" + location + "\nSUMMARY:" + summary + "\nEND:VEVENT";
}
function generate() {
var allocated;
try {
allocated = JSON.parse(document.getElementById("user-input").value);
} catch (e) {
alert("We got an error when parsing the input: " + e.toString());
}
var vEventString = Object.keys(allocated).map(function (key) {
return toVevent(allocated[key]);
}).join("\n");
var icalendar = "BEGIN:VCALENDAR\nVERSION:2.0\nCALSCALE:GREGORIAN\n" + timezoneInfo + vEventString + "\nEND:VCALENDAR";
download(icalendar, "allocateplus.ics", "text/calendar");
}
document.getElementById("generate-button").addEventListener("click", generate);
</script>
</body>
</html>