-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcal.html
executable file
·157 lines (139 loc) · 4.13 KB
/
cal.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script>
var title = 'Kalender';
var months = ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli',
'August', 'September', 'Oktober', 'November', 'Dezember'];
document.title = title;
function parseDate(date)
{
var tokens = date.split(' ');
var day = parseInt(tokens[0]);
var month = months.indexOf(tokens[1]);
var year = parseInt(tokens[2]);
if (month == -1)
{
throw('Invalid date: ' + date);
}
return new Date(year, month, day + 1);
};
function checkCalendar(fullYear, before)
{
var index = 0;
var total = 0;
var locations = {};
var calendar = JSON.parse(document.getElementById('calendar').value);
var last = new Date(0);
var today = new Date();
for (var index = 0; index < calendar.length; index++)
{
var ts = parseDate(calendar[index][0]);
var location = calendar[index][1];
if (before == null || ts <= before)
{
if (ts > last)
{
last = ts;
}
if (locations[location] == null)
{
locations[location] = 0;
}
locations[location] += 1;
total += 1;
}
}
if (!fullYear && last.getFullYear() == today.getFullYear())
{
last = (last < today) ? today : last;
}
else if (!fullYear && last.getFullYear() != today.getFullYear())
{
return '';
}
else if (fullYear || last.getFullYear() != today.getFullYear())
{
last = new Date(last.getFullYear(), 11, 31);
}
var start = new Date(last.getFullYear(), 0, 1);
var days = Math.ceil((last.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
locations['ZH'] = days - total;
var json = [];
for (var key in locations)
{
json.push({key: key, value: locations[key]});
}
json.sort(function(a, b){return b.value - a.value});
var result = [];
result.push('Von: ' + start.getDate() + '.' + (start.getMonth()+1) + '.' + start.getFullYear() +
' bis: ' + last.getDate() + '.' + (last.getMonth()+1) + '.' + last.getFullYear() +
' (' + days + ' Tage, ' + total + ' Einträge)');
for (var i = 0; i < json.length; i++)
{
var key = json[i].key;
var value = json[i].value;
var perc = Math.round(((value * 1000) / days)) / 10;
result.push(key + ': ' + value + ' (' + perc + '%)');
}
return result.join('\n');
};
function process()
{
try
{
var today = checkCalendar(false, new Date());
var partial = checkCalendar(false);
document.getElementById('result').value =
checkCalendar(true) + (partial.length > 0 ?
'\n\n' + partial + '\n\n' : '') + today + '\n';
}
catch (e)
{
document.getElementById('result').value = e;
}
};
function yearChanged()
{
var year = document.getElementById('year').value;
document.getElementById('calendarLink').href = 'https://calendar.google.com/calendar/u/0/r/' +
'search?q=Gaudenz%3A&cal=Y2FzYXdlcm5saUBnbWFpbC5jb20&start=' + year + '0101&end=' + year + '1231';
document.getElementById('calendar').value =
'var a=[];\n' +
'[].forEach.call(document.querySelectorAll("[data-datekey]"), (elt) => {\n' +
'var x = elt.getElementsByTagName("button")[0].getAttribute("aria-label").split(",").splice(0,2).join(",");\n' +
'var y = elt.firstChild.firstChild.nextSibling.firstChild.nextSibling.firstChild.getAttribute("aria-label");\n' +
'var temp = y.indexOf(" ("); temp = (temp == -1) ? y.indexOf(", Kalender") : temp;\n' +
'a.push([x.split(" ").splice(1).join(" ") + " " + ' + year + ',' +
'y.substring(y.indexOf(": ") + 2, temp)])' +
'});\n' +
'a;';
};
</script>
</head>
<body>
1. Enter year: <input id="year" type="text" size="4" onchange="yearChanged()">
<br>
2. Click on the link: <a href="" id="calendarLink" target="_blank">Google Kalender Entries</a>
<br>
3. Paste the following into the console
<br>
4. Right click the result, copy object and paste here
<br>
<textarea id="calendar" rows="10" cols="110">
</textarea>
<br><br>
<button id="process" onclick="process();">Process</button>
<br><br>
Result:
<br>
<textarea id="result" rows="28" cols="110">
</textarea>
<script>
var year = new Date().getFullYear();
document.getElementById('year').value = year;
yearChanged();
</script>
</body>
</html>