-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
194 lines (172 loc) · 5.24 KB
/
index.html
File metadata and controls
194 lines (172 loc) · 5.24 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Where are you?</title>
<meta name="description" content="Displays the city nearest to your current IP address.">
<meta name="theme-color" content="#0a0a0a">
<link rel="canonical" href="https://n7h.io/">
<meta property="og:type" content="website">
<meta property="og:url" content="https://n7h.io/">
<meta property="og:title" content="Where are you?">
<meta property="og:description" content="Displays the city nearest to your current IP address.">
<link rel="icon" type="image/svg+xml" href="favicon.svg">
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--bg: #0a0a0a;
--fg: #f0f0f0;
--muted: #555;
--toggle-bg: #222;
--toggle-active: #f0f0f0;
--toggle-active-fg: #0a0a0a;
--toggle-fg: #666;
}
[data-theme="light"] {
--bg: #f5f5f5;
--fg: #0a0a0a;
--muted: #888;
--toggle-bg: #e0e0e0;
--toggle-active: #0a0a0a;
--toggle-active-fg: #f5f5f5;
--toggle-fg: #999;
}
body {
min-height: 100dvh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: var(--bg);
color: var(--fg);
font-family: 'Georgia', serif;
overflow: hidden;
transition: background 0.3s ease, color 0.3s ease;
}
#city {
font-size: clamp(2.5rem, 10vw, 7rem);
font-weight: 400;
letter-spacing: 0.04em;
opacity: 0;
transform: translateY(12px);
transition: opacity 0.8s ease, transform 0.8s ease;
text-align: center;
padding: 0 1rem;
}
#city.visible {
opacity: 1;
transform: translateY(0);
}
#status {
margin-top: 1.2rem;
font-family: 'Courier New', monospace;
font-size: 0.75rem;
letter-spacing: 0.12em;
color: var(--muted);
text-transform: uppercase;
opacity: 0;
transition: opacity 0.6s ease 0.4s;
}
#status.visible { opacity: 1; }
#theme-toggle {
position: fixed;
bottom: 1.5rem;
right: 1.5rem;
display: flex;
gap: 2px;
background: var(--toggle-bg);
border-radius: 999px;
padding: 3px;
transition: background 0.3s ease;
}
#theme-toggle button {
border: none;
background: none;
cursor: pointer;
border-radius: 999px;
padding: 5px 8px;
font-size: 0.7rem;
font-family: 'Courier New', monospace;
letter-spacing: 0.06em;
color: var(--toggle-fg);
transition: background 0.2s ease, color 0.2s ease;
line-height: 1;
}
#theme-toggle button.active {
background: var(--toggle-active);
color: var(--toggle-active-fg);
}
</style>
</head>
<body>
<div id="city"></div>
<div id="status"></div>
<div id="theme-toggle">
<button data-mode="light">LIGHT</button>
<button data-mode="system">AUTO</button>
<button data-mode="dark">DARK</button>
</div>
<script>
const cityEl = document.getElementById('city');
const statusEl = document.getElementById('status');
// --- Theme ---
const STORAGE_KEY = 'theme-mode';
const systemDark = () => window.matchMedia('(prefers-color-scheme: dark)').matches;
function applyTheme(mode) {
const resolved = mode === 'system' ? (systemDark() ? 'dark' : 'light') : mode;
document.documentElement.setAttribute('data-theme', resolved);
document.querySelectorAll('#theme-toggle button').forEach(btn => {
btn.classList.toggle('active', btn.dataset.mode === mode);
});
}
let currentMode = localStorage.getItem(STORAGE_KEY) || 'system';
applyTheme(currentMode);
document.getElementById('theme-toggle').addEventListener('click', e => {
const btn = e.target.closest('button');
if (!btn) return;
currentMode = btn.dataset.mode;
localStorage.setItem(STORAGE_KEY, currentMode);
applyTheme(currentMode);
});
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
if (currentMode === 'system') applyTheme('system');
});
// --- Geolocation ---
function show(city, label) {
cityEl.textContent = city;
statusEl.textContent = label || '';
requestAnimationFrame(() => {
cityEl.classList.add('visible');
statusEl.classList.add('visible');
});
}
async function locate() {
const apis = [
{
url: 'https://ipwho.is/',
parse: d => d.success && d.city ? [d.city, d.country] : null,
},
{
url: 'https://ipapi.co/json/',
parse: d => !d.error && d.city ? [d.city, d.country_name] : null,
},
{
url: 'https://freeipapi.com/api/json',
parse: d => d.cityName ? [d.cityName, d.countryName] : null,
},
];
for (const api of apis) {
try {
const r = await fetch(api.url);
const d = await r.json();
const result = api.parse(d);
if (result) { show(...result); return; }
} catch (_) {}
}
show('Unknown', 'location unavailable');
}
locate();
</script>
</body>
</html>