forked from mionisation/icsMerge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·382 lines (336 loc) · 13.1 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
<!doctype html>
<html>
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-123653676-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-123653676-1');
</script>
<title>ics, iCalendar: Merge & Combine multiple .ics files</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="The easiest tool to merge and combine .ics / iCalendar files">
<meta name="subject" CONTENT="Combine and merge ICS and iCalendar files">
<meta name="Keywords" CONTENT="ICS merge combine calendar iCalendar">
<link href="https://fonts.googleapis.com/css?family=Bangers" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Oswald" rel="stylesheet">
<link rel="icon" type="image/png" href="favicon/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="favicon/favicon-16x16.png" sizes="16x16" />
<style>
html { overflow-y:scroll; min-height: 100% }
body {
text-align: center;
padding-top:10px;
min-height: 100%;
font-family: 'Oswald', sans-serif;
color: white;
font-size: 1.5rem;
background: linear-gradient(to bottom right, #dd6a83, #c63b59);
}
#drop_zone {
border: 2px dashed white;
height: 250px;
width: inherit;
margin: auto;
padding: 5px;
background: linear-gradient(to bottom left, #ff924c, #ff7b25);
border-radius: 8px;
outline: 2px dashed white;
outline-offset: -10px;
}
h1 {
text-align: center;
color: white;
font-size: 4rem;
letter-spacing: 5px;
font-family: 'Bangers', cursive, Arial;
}
textarea {
display: block;
color: black;
width: 100%;
margin: 50px auto 20px;
padding: 10px;
box-sizing: border-box;
background: linear-gradient(to bottom left, #ffedc4, #ffd6a0);
font-family: 'Consolas', 'Monaco','Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New';
}
@media (max-width:350px) {
#dragdropAnimation {
display: none;
}
}
#dragdropAnimation {
position: relative;
width: 100%;
height: 70%;
}
#dragdropAnimation img {
position:absolute;
}
@keyframes fileAnim {
25% {left:15%; top:5%; opacity: .9}
50% {left: 75%; top:23%; opacity: .9}
100% {left: 75%; top:23%; opacity: 0;}
}
#file {
top: 5%;
left: 15%;
z-index: 1;
width: 12%;
height: inherit;
display: block;
opacity: 0;
animation-name: fileAnim;
animation-iteration-count: infinite;
animation-duration: 4s;
}
#folder {
top: 5%;
right: 5%;
z-index: 3;
width: 30%;
height: inherit;
display: block;
opacity: .6;
}
@keyframes mouseAnim {
25% {left:20%; top:3%; opacity: .9}
50% {left: 80%; top:21%; opacity: .9}
100% {left: 80%; top:21%; opacity: 0;}
}
#mouse {
top: 20%;
left: 5%;
z-index: 2;
width: 3%;
height: inherit;
display: block;
animation-name: mouseAnim;
animation-iteration-count: infinite;
animation-duration: 4s;
opacity: 0;
}
a {
color: white;
text-decoration: underline;
}
.button {
display: inline-block;
margin-top: 10px;
padding: 10px 20px;
font-size: 20px;
cursor: pointer;
text-align: center;
text-decoration: none;
outline: none;
color: #fff;
background-color: #ff7b25;
border: none;
border-radius: 15px;
box-shadow: -1px 5px #ddd;
font-family: 'Oswald', sans-serif;
}
.button:hover {background-color: #a34e16}
.button:active {
background-color: #a34e16;
box-shadow: -1px 3px #999;
transform: translateY(4px);
}
#content {
max-width: 600px;
min-width: 250px;
margin: 0 auto;
background: none;
color: #fff;
}
#fileChooserLabel {
text-decoration: underline;
cursor: pointer;
}
#fileChooser {
display: none;
}
</style>
<script src="https://cdn.rawgit.com/konvajs/konva/1.7.6/konva.min.js"></script>
</head>
<body>
<script>
var data = undefined;
function download_merge(data) {
var fileContent = '';
if( data == null | data == undefined ) {
writeMessage("ERROR: Please select or drag your *.ics files first!");
return;
}
data.forEach(function(row) {
fileContent += row;
fileContent += "\n";
});
var element = document.createElement('a');
element.setAttribute('href', 'data:text/ics;charset=utf-8,' + encodeURIComponent(fileContent));
element.setAttribute('download', 'calendar.ics');
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
function writeMessage(text) {
var message = document.getElementById('message');
message.innerHTML=text;
setTimeout(function() {message.innerHTML=""}, 3500);
}
function processFile(i, size, file, callback) {
var reader = new FileReader();
reader.onload = function(event)
{
// NOTE: event.target point to FileReader
var contents = event.target.result;
var lines = contents.split('\n');
// Remove all trailing new lines and whitespaces
for (var j = 0; j < lines.length; j++) {
lines[j] = lines[j].replace(/\s+$/, '');
}
var beginEvent = lines.indexOf("BEGIN:VEVENT");
var endEvent = lines.lastIndexOf('END:VEVENT');
if (size == 1) {
// do nothing
} else if(i == 0) {
//First calendar file entry: Takes in also first part of meta data
lines = lines.slice(0, endEvent + 1);
} else if ( i == (size - 1)) {
//Last calendar file entry: Take last part of meta data
lines = lines.slice(beginEvent);
} else {
// Slice only Event information, beginnen and ending with "VEVENT" headers
lines = lines.slice(beginEvent, endEvent + 1);
}
callback(i, size, lines);
};
reader.readAsText(file);
}
function dragOverHandler(ev) {
// Prevent default behavior (Prevent file from being opened)
ev.preventDefault();
writeMessage("Drop the files!");
}
function selectHandler(ev) {
var allDates = [];
var size = ev.srcElement.files.length;
writeMessage(size + " file(s) selected! Downloading result...");
for (var i = 0; i < size; i++) {
var file = ev.srcElement.files[i];
console.log('... file[' + i + '].name = ' + ev.srcElement.files[i].name);
processFile(i, size, file, function(i, size, content){
allDates = allDates.concat(content);
if(i == size - 1) {
// Final callback
document.getElementById('output').innerHTML=allDates.join('\n');
download_merge(allDates);
data = allDates;
}
});
}
}
function dropHandler(ev) {
// Prevent default behavior (Prevent file from being opened)
ev.preventDefault();
if (ev.dataTransfer.items) {
// Use DataTransferItemList interface to access the file(s)
var allDates = [];
var size = ev.dataTransfer.items.length;
writeMessage(size + " file(s) dropped! Downloading result...");
for (var i = 0; i < size; i++) {
// If dropped items aren't files, reject them
if (ev.dataTransfer.items[i].kind === 'file') {
var file = ev.dataTransfer.items[i].getAsFile();
console.log('... file[' + i + '].name = ' + file.name);
processFile(i, size, file, function(i, size, content){
allDates = allDates.concat(content);
if(i == size - 1) {
// Final callback
document.getElementById('output').innerHTML=allDates.join('\n');
download_merge(allDates);
data = allDates;
}
});
}
}
} else {
// Use DataTransfer interface to access the file(s)
var size = ev.dataTransfer.files.length;
var allDates = [];
for (var i = 0; i < size; i++) {
var file = ev.dataTransfer.files[i];
console.log('... file[' + i + '].name = ' + ev.dataTransfer.files[i].name);
processFile(i, size, file, function(i, size, content){
allDates = allDates.concat(content);
if(i == size - 1) {
// Final callback
document.getElementById('output').innerHTML=allDates.join('\n');
download_merge(allDates);
data = allDates;
}
});
}
}
// Pass event to removeDragData for cleanup
removeDragData(ev)
}
function removeDragData(ev) {
// clear all cached data
if (ev.dataTransfer.items) {
// Use DataTransferItemList interface to remove the drag data
ev.dataTransfer.items.clear();
} else {
// Use DataTransfer interface to remove the drag data
ev.dataTransfer.clearData();
}
}
function openMessage(element, message) {
if (element.innerHTML == undefined | element.innerHTML == null | element.innerHTML == '' ) {
element.innerHTML = message;
} else {
element.innerHTML = '';
}
}
function openAbout() {
document.getElementById('credits').innerHTML = '';
var about = 'iCalendar (.ics) files are a <a href="https://en.wikipedia.org/wiki/ICalendar">collection of events with metadata</a>. Sometimes, you end up with a lot of them, but some calendars (e.g. Google Calendar) only support import from single .ics files. This tool combines the events and adds metadata to the result for the .ics files you upload, so you don\'t have to import each single one by hand.';
var aboutEl = document.getElementById('about');
openMessage(aboutEl, about);
}
function openCredits() {
document.getElementById('about').innerHTML = '';
var credits = 'Find the source for this site <a href="https://github.com/mionisation/icsMerge">on Github</a><br><a href="mailto:michael.antonius.ion@gmail.com?subject=ICS%20merger"> Contact me for questions and remarks </a><br> <a href="https://www.linkedin.com/in/michael-ion">More about me</a> <br>Animation made using (and slightly altering) <a href="https://fontawesome.com">fontawesome icons</a> <br> Fonts from Google Fonts: <a href="https://fonts.google.com/specimen/Oswald">Oswald</a> and <a href="https://fonts.google.com/specimen/Bangers">Bangers</a>';
var creditEl = document.getElementById('credits');
openMessage(creditEl, credits);
}
</script>
<a href="https://github.com/mionisation/icsMerge"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png" alt="Fork me on GitHub"></a>
<h1>Merge .ICS Files - Fast, Simple, Easy!</h1>
<p>Got some .ics files to merge into one? You're in the right place! </p>
<div id="content">
<div id="drop_zone" ondrop="dropHandler(event);" ondragover="dragOverHandler(event);">
<div id="dragdropAnimation">
<img id="mouse" src="mouse-pointer.svg" />
<img id="folder" src="folder.svg" />
<img id="file" src="file.svg" />
</div>
<label for="fileChooser" id="fileChooserLabel">Select</label>
<input type="file" id="fileChooser" name="fileChooser" onchange="selectHandler(event)" accept=".ics" multiple>
or drag all your .ICS calendar files here!
</div>
<button class="button" onclick="download_merge(data)">Click for manual download!</button>
<p id="message"></p>
<textarea id="output" rows="15" >(If the donwload doesn't work, you can also copy the result here and paste to a new .ics file!)</textarea>
<p><a underline, mousepointer onclick="openAbout()">( What's this? )</a></p>
<p id="about"></p>
<p><a underline, mousepointer onclick="openCredits()">( Credits )</a></p>
<p id="credits"></p>
</div>
</body>
</html>