-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathiOSCal.coffee
255 lines (200 loc) · 7.55 KB
/
iOSCal.coffee
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
#color settings for calendars
#color is in format suitable for css
calendars = [
{name:"prednasky",color:"gold"},
{name:"cvika",color:"mediumseagreen"},
{name:"Sviatky na Slovensku",color:"mediumpurple"},
{name:"zadania/zapocty/deadlines",color:"crimson"}
]
#mode of widget (light)
mode = "dark"
#Default color of calendar
defColor = "white"
# Bash command to pull events from icalBuddy
# Set +2 to how many days you want to show
# icalBuddy has more functionality that can be used here
command: "/usr/local/bin/icalbuddy -n eventsToday+1"
# Update is called once per hour
refreshFrequency: "1h"
#=== DO NOT EDIT AFTER THIS LINE unless you know what you're doing! ===
#======================================================================
# CSS styling
style: """
color: white
font-family: SF Pro Rounded
font-weight: 400
width: 100%
height: 220px
position: absolute
top: 33%
font-size: 14px
#calendar
border-radius: 10px
-webkit-backdrop-filter: blur(20px)
width: 410px
height: 200px
position: absolute
top: 0
left 50%
transform: translate(-50%,0)
padding: 40px 20px 20px 20px
-webkit-box-shadow: 10px 10px 47px 0px rgba(0,0,0,0.54)
letter-spacing: 1px
#calendar.dark
background-color: rgba(0,0,0,0.45)
#calendar.light
background-color: rgba(255,255,255,0.5)
color: black
#calendar.light header, #calendar.light .leftBox .time .to, #calendar.light .rightBox .location
color: rgba(50,50,50,0.8)
#calendar.dark header, #calendar.dark .leftBox .time .to, #calendar.dark .rightBox .location
color: rgba(200,200,200,0.8)
header
padding: 10px 0 10px 0
display: flex
flex-direction: row
position: fixed
top: 0
header img
width: 20px
margin-right: 10px
header .widgetName
line-height: 20px
.mainBox
overflow-y: scroll
height: 100%
.eventBox
display: flex
flex-direction: column
.today h2
margin-top: 10px
.event
padding: 5px
display: flex
flex-direction: row
//border-top: 1px solid rgba(200,200,200,0.3)
.event .title
line-height: 20px
.event .leftBox
width: 10%
padding: 0 10px 0 0
margin: 0 5px 0 0
border-right: 2px solid
.leftBox .time
text-align: right
.leftBox .time .from
line-height: 20px
.leftBox .time .to
font-size: 12px;
line-height: 20px
.rightBox .location
font-size: 12px
line-height: 20px
.nothing
text-align: center
margin-top: 10px
"""
# Initial render
render: (output) -> """<div id='calendar' class='#{mode}'>#{output}</div>"""
# Update when refresh occurs
update: (output, domEl) ->
getCalendarColor = (calendarName) ->
for i in calendars
if i.name == calendarName
return i.color
return defColor
lines = output.split('• ')
lines = lines.map((str) => ({event:str}))
for i in [0...lines.length]
lines[i].event = lines[i].event.split('\n')
lines.splice(0,1)
for i in [0...lines.length]
name = lines[i].event[0];
location = lines[i].event[1];
if ( location.includes('location:'))
location = location.replace('location:','')
location = location.replace(/\s/g, '')
time = lines[i].event[2];
if (time.includes(' '))
time = time.replace(' ', '')
lines[i].event = {"name":name,"location":location,"time":time}
inner = ''
inner += "<header><img src='ubersicht-ios-clock-upnext-weather.widget/icons/calendar.png' alt='icon'></img><div class='widgetName'>UP NEXT</div></header>"
today = []
tomorrow = []
for i in [0...lines.length]
if (lines[i].event.time.includes('today'))
lines[i].event.time = lines[i].event.time.replace("today at ","")
#lines[i].event.name = lines[i].event.name.replace(/\([A-z]*\)/i, "")
lines[i].event.time = lines[i].event.time.split(' - ')
today.push(lines[i].event)
continue
else if(lines[i].event.location.includes('today'))
lines[i].event.location = ""
lines[i].event.time = "Whole - Day"
#lines[i].event.name = lines[i].event.name.replace(/\([A-z]*\)/i, "")
lines[i].event.time = lines[i].event.time.split(' - ')
today.push(lines[i].event)
continue
else if (lines[i].event.time.includes('tomorrow'))
lines[i].event.time = lines[i].event.time.replace("tomorrow at ","")
#lines[i].event.name = lines[i].event.name.replace(/\([A-z]*\)/i, "")
lines[i].event.time = lines[i].event.time.split(' - ')
tomorrow.push(lines[i].event)
continue
else if(lines[i].event.location.includes('tomorrow'))
lines[i].event.location = ""
lines[i].event.time = "Whole - Day"
#lines[i].event.name = lines[i].event.name.replace(/\([A-z]*\)/i, "")
lines[i].event.time = lines[i].event.time.split(' - ')
tomorrow.push(lines[i].event)
continue
inner += "<div class='mainBox'>"
inner += "<div class='today eventBox'>"
if today.length > 0
inner += "<h2>Today</h2>"
for i in [0...today.length]
name = today[i].name
calendarName = name.match(/\([a-zA-Z0-9\/\s]*?\)$/gmi)
calendarName = calendarName[0].replace(/[\(-\)]+/gm,"")
calendarColor = getCalendarColor(calendarName)
name = name.replace(/\([a-zA-Z0-9\/\s]*?\)$/gmi, "")
loc = today[i].location
time = today[i].time
inner += "<div class='event'><div class='leftBox' style=' border-color: #{calendarColor}'><div class='time'><div class='from'>"
inner += time[0]
inner += "</div><div class='to'>"
inner += time[1]
inner += "</div></div></div><div class='rightBox'><div class='title'>"
inner += name
inner += "</div><div class='location'>"
inner += loc
inner += "</div></div></div>"
else
inner += "<div class='nothing'>No events today</div>"
inner += "</div>"
inner += "<div class='tomorrow eventBox'>"
if tomorrow.length > 0
inner += "<h2>Tomorrow</h2>"
for i in [0...tomorrow.length]
name = tomorrow[i].name
calendarName = name.match(/\([a-zA-Z0-9\/\s]*?\)$/gmi)
calendarName = calendarName[0].replace(/[\(-\)]+/gm,"")
calendarColor = getCalendarColor(calendarName)
name = name.replace(/\([a-zA-Z0-9\/\s]*?\)$/gmi, "")
loc = tomorrow[i].location
time = tomorrow[i].time
inner += "<div class='event'><div class='leftBox' style=' border-color: #{calendarColor}'><div class='time'><div class='from'>"
inner += time[0]
inner += "</div><div class='to'>"
inner += time[1]
inner += "</div></div></div><div class='rightBox'><div class='title'>"
inner += name
inner += "</div><div class='location'>"
inner += loc
inner += "</div></div></div>"
else
inner += "<div class='nothing'>No events tomorrow</div>"
inner += "</div>"
inner += "</div>"
$(calendar).html(inner)