-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.html
More file actions
115 lines (105 loc) · 3.67 KB
/
index.html
File metadata and controls
115 lines (105 loc) · 3.67 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Ruuvi Station" />
<meta name="robots" content="noindex">
<link rel="icon" href="/favicon-32x32.png" sizes="32x32" />
<link rel="icon" href="/android-chrome-192x192.png" sizes="192x192" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<meta name="msapplication-TileImage" content="/android-chrome-512x512.png" />
<link rel="manifest" href="/manifest.json" />
<title>Ruuvi Station</title>
<style>
#init_loading {
position: absolute;
top: 50%;
left: 50%;
margin-top: -50px;
margin-left: -50px;
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root">
<div id="init_loading">
<center>
<img width="50px" src="/android-chrome-192x192.png" />
</center>
</div>
</div>
<script type="module" src="/src/index.jsx"></script>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
<script>
let bgMode = localStorage.getItem("chakra-ui-color-mode") || "dark"
let bgColor = bgMode === "dark" ? "#001b1a" : "#edf2f2"
document.body.style.background = bgColor
document.querySelector('meta[name="theme-color"]').setAttribute('content', bgColor);
try {
let cookie = document.cookie;
if (cookie) {
let keys = cookie.split(";")
keys.forEach(key => {
if (key.indexOf("station_user=") !== -1) {
let payload = key.replace("station_user=", "")
//console.log("found station user cookie")
let parsed = JSON.parse(payload)
if (parsed && parsed.accessToken) {
let domain = ".ruuvi.com"
document.cookie = `station_user=;domain=${domain};Max-Age=-99999999`
document.cookie = `station_status=signedIn;domain=${domain};Max-Age=99999999`
localStorage.setItem("user", JSON.stringify(parsed))
}
}
});
}
} catch (e) {
console.log("could not parse cookie", e)
}
function goToLoginPage() {
if (window.location.href.indexOf("loginmethod=legacy") !== -1) {
// lets keep the old way too in case it's needed
return
}
if (window.location.href.indexOf("devstation") !== -1) {
window.location.href = "https://ruuvi.com/devstation"
return
}
else if (window.location.href.indexOf("localhost") !== -1) {
// is localhost, not navigating anywhere
return
}
window.location.href = "https://ruuvi.com/station"
}
function getUser() {
var user = localStorage.getItem("user");
return user ? JSON.parse(user) : null;
}
function isStaging() {
return window.location.href.indexOf("/staging") !== -1
}
function getUserKey() {
return isStaging() ? "staging_user" : "user"
}
if (!isStaging() && !getUser()) {
localStorage.removeItem(getUserKey())
let domain = ".ruuvi.com"
document.cookie = `station_status=signedIn;domain=${domain};Max-Age=-99999999`
localStorage.clear();
goToLoginPage()
}
</script>
</body>
</html>