forked from Pe8er/Strava.widget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.coffee
188 lines (156 loc) · 4.51 KB
/
index.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
# Created by Pe8er (https://github.com/Pe8er)
# Modified by stvhwrd
options =
# Easily enable or disable the widget.
widgetEnable : true
# Your Strava user ID. It's at the end of your profile page URL.
myid : "5640764"
# Your Strava authorization token. Get one here - www.strava.com/settings/api.
token : "6a6ede467e22b514b7d418b5d422396354f1ec69"
# Distance units: KM for kilometers or M for miles.
units : "KM"
# Your yearly biking goal in kilometers.
yearlygoal : "4000"
# Stick the widget in the bottom right corner? Set to *true* if you're using it with Sidebar widget, set to *false* if you'd like to give it some breathing room and a drop shadow.
stickInCorner : false
refreshFrequency: '1h'
command: "osascript Strava.widget/Strava.applescript #{options.myid} #{options.token} #{options.units} #{options.yearlygoal}"
style: """
// A few useful variables.
white1 = rgba(white,1)
white05 = rgba(white,0.5)
white02 = rgba(white,0.2)
if #{options.stickInCorner} == false
margin = 20px
box-shadow 0 20px 50px 10px rgba(0,0,0,.6)
else
margin = 0
transform-style preserve-3d
top margin
left margin
width 300px
overflow hidden
white-space nowrap
position relative
-webkit-backdrop-filter blur(20px) brightness(70%) contrast(120%) saturate(140%)
font-family system, -apple-system
opacity 0
display none
*, *:before, *:after
box-sizing border-box
.wrapper
font-size 10pt
line-height 13pt
color white
padding 8px
height auto
.week, .month, .year
width 100%
margin-bottom 4px
.left
opacity 0.5
float left
.wDistance, .mDistance, .yDistance
display block
margin 0 0 0 auto
font-weight 700
text-align right
.bars
margin 4px 0 8px 0
height 8px
position relative
.bar, .progress, .goal
top 0
left 0
background-color white02
height 8px
width 100%
max-width 100%
min-width 1%
z-index 1
position absolute
.goal
background-color white02
z-index 2
width 2%
.progress
background-color white
z-index 3
width 1%
.outdone
background none
height 12px
border-right 1px solid white05
"""
options : options
render: (output) ->
# Initialize our HTML.
stravaHTML = ''
# Create the DIVs for each piece of data.
stravaHTML = "
<img src='Strava.widget/slim-strava-banner.png' width='300'>
<div class='wrapper'>
<div class='week'>
<span class='left'>Week</span>
<span class='wDistance'>No Data</span>
<div class='bars'>
<div class='bar'></div>
<div class='bar progress'></div>
<div class='bar goal'></div>
</div>
</div>
<div class='year'>
<span class='left'>Year</span>
<span class='yDistance'>No Data</span>
<div class='bars'>
<div class='bar'></div>
<div class='bar progress'></div>
<div class='bar goal'></div>
</div>
</div>
</div>"
return stravaHTML
# Update the rendered output.
update: (output, domEl) ->
# Get our main DIV.
div = $(domEl)
if @options.widgetEnable
# Get our pieces.
values = output.slice(0,-1).split("~")
# Initialize our HTML.
stravaHTML = ''
if values[0] != "NA"
# Define variables
wDistance = values[0]
wProgress = values[1]
wGoal = values[2]
mDistance = values[0]
mProgress = values[1]
mGoal = values[2]
yDistance = values[3]
yProgress = values[4]
yGoal = values[5]
# Update text values
div.find('.wDistance').html(wDistance)
div.find('.mDistance').html(mDistance)
div.find('.yDistance').html(yDistance)
# Update bar widths
div.find('.week .progress').css('width', wProgress)
div.find('.week .goal').css('width', wGoal)
div.find('.year .progress').css('width', yProgress)
div.find('.year .goal').css('width', yGoal)
if parseInt(yGoal) < parseInt(yProgress)
div.find('.year .goal').addClass('outdone')
if parseInt(wGoal) < parseInt(wProgress)
div.find('.week .goal').addClass('outdone')
# Show the damn thing!
div.css('display', 'block')
div.animate {opacity: 1}, 250, 'swing'
else
div.css('display', 'none')
div.animate {opacity: 0}, 250, 'swing'
# Sort out flex-box positioning.
div.parent('div').css('order', '4')
div.parent('div').css('flex', '0 1 auto')
else
div.hide()