forked from gabrielsroka/gabrielsroka.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.htm
208 lines (194 loc) · 7 KB
/
home.htm
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
<!doctype html>
<html>
<head>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<title>My Apps</title>
<style>
body {
font-family: sans-serif;
font-size: 13px;
}
nav, .widget {
margin: 24px;
}
.hide {
display: none;
}
#menu li {
padding: 10px 0;
}
a:active, a:link, a:visited, span, .app-button-name {
text-decoration: none;
color: black;
}
@media (prefers-color-scheme: dark) {
body {
background-color: #121212;
color: white;
}
a:active, a:link, a:visited, span, .app-button-name {
color: white;
}
}
#stocks td {
width: 33%;
height: 22px;
}
ul {
padding: 0;
list-style-type: none;
}
.app-button-wrapper {
float: left;
width: 98px;
}
@media (orientation: landscape) {
.app-button-wrapper {
width: 95px;
}
}
.app-button .logo {
width: 32px;
padding: 16px;
margin: 16px 16px 0;
border: solid 1px gray;
border-radius: 10px;
}
.app-button-name {
margin: 8px 4px;
text-align: center;
}
</style>
</head>
<body>
<nav>
<span id=burger style='font-size: 24px;'>≡</span>
<span id=notificationMenu style='float: right;'>🔔</span>
<ul id=menu class=hide>
<li><a href="/">Gabriel Sroka</a>
<li><a href='https://gsroka-neto.oktapreview.com'>Okta Home</a>
<li><span id=refresh>Refresh</span>
<li><a href='/login.htm?signout'>Sign out</a>
</ul>
</nav>
<main>
<div id=notifications class='widget hide'>
<div><a href='https://status.okta.com' style='font-weight: bold;'>Okta Status</a></div>
<a id=notificationLink></a><span id=seen style='float: right;'></span>
</div>
<div id=weather style='height: 80px;' class=widget>Loading <a href='https://www.google.com/search?q=weather'>weather</a>...</div>
<div id=stocks class=widget>
<table>
<tr><td><a href='https://www.google.com/search?q=okta stock'>Okta</a><td>123.45
<td><a href='https://www.google.com/search?q=aapl stock'>Apple</a><td>123.45
<tr><td><a href='https://www.google.com/search?q=goog stock'>Google</a><td>123.45
<td><a href='https://www.google.com/search?q=msft stock'>Microsoft</a><td>123.45
</table>
</div>
<div id=apps></div>
</main>
<script>
// For this to work, enable CORS in Okta: Security > API > Trusted Origins > Add Origin > CORS.
const baseUrl = 'https://gsroka-neto.oktapreview.com';
const latlong = '33.7737,-118.1365'; // or use getPosition below...
const rssKey = 'bktpucfcehpay70oarqhspsrzyt9wbjebfvhqkwb'; // you need your own... they're free from https://rss2json.com and you can lock it to your domain
onload = () => {
burger.onclick = () => menu.classList.toggle('hide');
notificationMenu.onclick = () => notifications.classList.toggle('hide');
getNotifications();
refresh.onclick = async () => showLinks(await getLinks());
if (localStorage.links) {
showLinks(JSON.parse(localStorage.links));
} else {
refresh.onclick();
}
getWeather();
};
async function getLinks() {
/* Fetch appLinks whose labels are in the following format:
label[, url, icon]
eg: "NY Times, nytimes.com", or just "NY Times"
If url is blank, it will figure it out from the label. It will remove spaces, and add "https://" and ".com", etc.*/
apps.innerHTML = 'Loading...';
try {
const init = {credentials: 'include'};
// const init = {mode: 'cors'}; // This didn't seem to work.
const response = await fetch(`${baseUrl}/api/v1/users/me/appLinks`, init);
const links = (await response.json())
.sort((link1, link2) => link1.sortOrder < link2.sortOrder ? -1 : 1)
.map(link => {
var [label, url, icon] = link.label.split(/,/);
url = url ? url.trim() : label.replace(/ /g, '');
if (!url.startsWith('https')) url = 'https://' + url;
if (!url.includes('.')) url += '.com';
if (icon) {
icon = icon.trim();
return {label, url, icon};
}
return {label, url};
});
localStorage.links = JSON.stringify(links);
return links;
} catch (e) {
apps.innerHTML = e + ' error. <a href="/login.htm"><u>Sign in</u></a>. Are third-party/cross-site cookies enabled?';
}
}
function showLinks(links) {
const lis = links.map(link => `<li class='app-button-wrapper'>` +
`<a href='${link.url}' target=_blank class='app-button' rel=noopener><img src='${link.icon || new URL(link.url).origin + '/favicon.ico'}' class='logo'/></a>` +
`<p class='app-button-name'>${link.label}`);
apps.innerHTML = `<ul>${lis.join('')}</ul>`;
}
async function getWeather() {
const forecast = await getForecast();
const hi = Math.max(forecast.daily[0].temperature, forecast.daily[1].temperature);
const lo = Math.min(forecast.daily[0].temperature, forecast.daily[1].temperature);
weather.innerHTML = "<a href='https://www.google.com/search?q=weather'>" +
`${hi}° ↑ • ${lo}° ↓ (${forecast.upd})` +
`<span style='float: right;'>${forecast.hourly.shortForecast}</span>` +
`<div><span style='font-size: 64px;'>${forecast.hourly.temperature}°</span>` +
`<span style='float: right;'><img src='${forecast.hourly.icon}' style='margin-top: 4px;'></span></div></a>`;
}
async function getForecast() {
// const {coords} = await getPosition();
// const latlong = coords.latitude + ',' + coords.longitude;
var response = await fetch('https://api.weather.gov/points/' + latlong);
const point = await response.json();
response = await fetch(point.properties.forecast);
const daily = await response.json();
response = await fetch(point.properties.forecastHourly);
const hourly = await response.json();
return {
daily: daily.properties.periods,
hourly: hourly.properties.periods[0],
upd: new Date(daily.properties.generatedAt).toLocaleString(undefined, {hour: 'numeric', minute: 'numeric'})
};
}
// function getPosition() {
// return new Promise(resolve => navigator.geolocation.getCurrentPosition(resolve));
// }
async function getNotifications() {
const response = await fetch(`https://api.rss2json.com/v1/api.json?rss_url=https://feeds.feedburner.com/OktaTrustRSS&api_key=${rssKey}&count=1`);
const feed = await response.json();
const item = feed.items[0];
notificationLink.href = item.link;
notificationLink.innerHTML = item.title
seen.innerHTML = new Date(item.pubDate + 'Z').toLocaleString(undefined, {month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric'});
const seenNotifications = JSON.parse(localStorage.notifications || '[]');
const guid = item.guid.split('/').pop();
if (seenNotifications.includes(guid)) {
seen.innerHTML += '✓';
} else {
seen.onclick = () => {
seen.innerHTML += '✓';
seen.onclick = null;
notifications.classList.add('hide')
seenNotifications.push(guid);
localStorage.notifications = JSON.stringify(seenNotifications);
};
notifications.classList.remove('hide');
}
}
</script>
</body>
</html>