-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulator.html
More file actions
212 lines (186 loc) · 6.48 KB
/
simulator.html
File metadata and controls
212 lines (186 loc) · 6.48 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>dayshere</title>
<style>
:root{
--bg: transparent;
--fg: #0f0f0f;
--size: 2rem;
--mobile-size: 1.5rem;
--font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans";
}
html,body{
margin: 6px;
padding:0;
background: var(--bg);
color: var(--fg);
font-family: var(--font);
-webkit-font-smoothing:antialiased;
-moz-osx-font-smoothing:grayscale;
}
.wrap{
padding: 12px 12px 4px;
box-sizing: border-box;
min-width: 0;
}
#countup{
font-size: var(--size);
line-height: 1.3;
white-space: pre-line;
word-break: break-word;
}
@media (max-width: 480px){
#countup{ font-size: var(--mobile-size); }
}
.toggle-row{
display:flex;
align-items:center;
gap:12px;
user-select:none;
font-size: 0.9rem;
opacity:0.9;
margin-bottom:8px;
flex-wrap: wrap;
}
.toggle-row label{
display:inline-flex;
align-items:center;
gap:8px;
cursor:pointer;
}
.toggle-row input[type="checkbox"]{
width:16px; height:16px;
margin:0px;
accent-color: currentColor;
cursor:pointer;
}
/* Quando marcado, força texto claro; quando desmarcado, escuro */
body.black { --fg: #f2f2f2; }
body:not(.black) { --fg: #0f0f0f; }
/* Campo de data/hora */
.dt-field{
display:inline-flex;
align-items:center;
gap:8px;
}
.dt-field input[type="datetime-local"]{
font: inherit;
padding: 2px 6px;
border: 1px solid #ccc;
border-radius: 6px;
background: transparent;
color: var(--fg);
}
.dt-field input[type="datetime-local"]::-webkit-calendar-picker-indicator{
filter: invert(0); /* mantém padrão; o texto segue var(--fg) */
}
</style>
</head>
<body>
<div id="countup" role="status" aria-live="polite"></div>
<div class="wrap">
<div class="toggle-row">
<label for="deathToggle">
<input id="deathToggle" type="checkbox" aria-label="death">
death
</label>
<label for="txtToggle">
<input id="txtToggle" type="checkbox" aria-label="light-mode">
light mode
</label>
</div>
<label class="dt-field" for="targetInput">
<input id="targetInput" type="datetime-local" aria-label="target date and time">
</label>
</div>
<script>
/* CONFIGURAÇÕES */
const TARGET_ISO = "1978-03-11T09:00:00";
const SHOW_ZERO_UNITS = true;
/* LÓGICA DO COUNTUP */
const countupEl = document.getElementById("countup");
const plural = (v, s, p) => `${v} ${v === 1 ? s : p}`;
const targetInput = document.getElementById("targetInput");
let timer = null;
// Converte ISO para valor aceitável por <input type="datetime-local"> (local, sem segundos)
const pad = n => String(n).padStart(2,'0');
function isoToLocalValue(iso){
const d = new Date(iso);
const yyyy = d.getFullYear();
const mm = pad(d.getMonth()+1);
const dd = pad(d.getDate());
const hh = pad(d.getHours());
const mi = pad(d.getMinutes());
return `${yyyy}-${mm}-${dd}T${hh}:${mi}`;
}
// Converte valor do input (local) para Date local
function inputToDate(val){
if(!val) return new Date(TARGET_ISO);
const [datePart, timePart] = val.split('T');
const [y,m,d] = datePart.split('-').map(Number);
const [hh,mi] = timePart.split(':').map(Number);
return new Date(y, m-1, d, hh, mi, 0, 0);
}
// baseTarget mutável via input; inicializa com TARGET_ISO
targetInput.value = isoToLocalValue(TARGET_ISO);
let baseTarget = inputToDate(targetInput.value);
/* Toggle death_mode */
let death_mode = false;
const deathToggle = document.getElementById("deathToggle");
death_mode = deathToggle.checked;
deathToggle.addEventListener('change', (e) => {
death_mode = e.target.checked;
// updateCountup(); // opcional
});
// Atualiza baseTarget ao mudar o input
targetInput.addEventListener('change', () => {
baseTarget = inputToDate(targetInput.value);
// updateCountup(); // opcional
});
function updateCountup(){
const now = new Date();
// target efetivo: baseTarget (+85 anos se death_mode)
const target = new Date(baseTarget);
if (death_mode) {
target.setFullYear(target.getFullYear() + 85);
}
// sign = 1 (elapsed: now - target), -1 (remaining: target - now)
const sign = death_mode ? -1 : 1;
let years = sign * (now.getFullYear() - target.getFullYear());
let months = sign * (now.getMonth() - target.getMonth());
let days = sign * (now.getDate() - target.getDate());
let hours = sign * (now.getHours() - target.getHours());
let minutes = sign * (now.getMinutes() - target.getMinutes());
let seconds = sign * (now.getSeconds() - target.getSeconds());
if (seconds < 0) { seconds += 60; minutes--; }
if (minutes < 0) { minutes += 60; hours--; }
if (hours < 0) { hours += 24; days--; }
if (days < 0) {
const prevMonthDays = new Date(now.getFullYear(), now.getMonth(), 0).getDate();
days += prevMonthDays;
months--;
}
if (months < 0) { months += 12; years--; }
const parts = [];
if (years > 0 || SHOW_ZERO_UNITS) parts.push(plural(Math.max(years,0), "ano", "anos"));
if (months > 0 || SHOW_ZERO_UNITS) parts.push(plural(Math.max(months,0), "mês", "meses"));
if (SHOW_ZERO_UNITS || days > 0) parts.push(plural(days, "dia", "dias"));
if (SHOW_ZERO_UNITS || hours > 0) parts.push(plural(hours, "hora", "horas"));
if (SHOW_ZERO_UNITS || minutes > 0) parts.push(plural(minutes, "minuto", "minutos"));
if (SHOW_ZERO_UNITS || seconds >= 0)parts.push(plural(seconds, "segundo","segundos"));
countupEl.textContent = parts.join("\n");
}
updateCountup();
timer = setInterval(updateCountup, 1000);
/* Toggle light mode */
const toggle = document.getElementById("txtToggle");
document.body.classList.toggle('black', toggle.checked);
toggle.addEventListener('change', (e) => {
document.body.classList.toggle('black', e.target.checked);
});
</script>
</body>
</html>