This repository has been archived by the owner on May 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.html
176 lines (169 loc) · 4.31 KB
/
timer.html
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
<center><select id="countdowns"></select></center>
<div id="cd0" style="opacity: 1"></div>
<div id="cd1" style="opacity: 0"></div>
<input id="fore" type="color" value="#ff0000" />
<input id="back" type="color" value="#000000" oncontextmenu="tryEgg(event);" />
<style>
@import url("https://fonts.googleapis.com/css2?family=VT323&display=swap");
body {
font-family: "VT323", monospace;
background-color: black;
color: red;
overflow: hidden;
}
#cd0, #cd1 {
font-size: 50vh;
max-width: 100%;
text-align: center;
position: absolute;
display: block;
left: 50%;
top: 50%;
text-align: center;
transform: translate(-50%, -50%);
}
#cd0[data-active], #cd1[data-active] {
transition: opacity 0.5s;
}
select {
background: none;
font: inherit;
font-size: 10vh;
color: inherit;
border: none;
}
option {
background: none !important;
}
input {
background: none;
border: none;
outline: none;
padding: 0px;
}
</style>
<script>
Object.defineProperties(window, {
Foreground: {
get() {
return document.getElementById("fore").value
},
},
EggAvailable: {
get() {
return (
Foreground == "#000000" &&
Background == "#2a0045" &&
selector.value == "DONUT"
)
},
},
Background: {
get() {
return document.getElementById("back").value
},
},
})
{
let lastHour = new Date().getHours()
const f = () => {
if (new Date().getHours() !== lastHour) {
fixGoals()
lastHour = new Date().getHours()
}
}
setInterval(f, 60000)
}
function getTimeRemaining(endtime) {
const total = Date.parse(endtime) - Date.parse(new Date())
const ms = total
const seconds = Math.floor((total / 1000) % 60)
const minutes = Math.floor((total / 1000 / 60) % 60)
const hours = Math.floor((total / (1000 * 60 * 60)) % 24)
const days = Math.floor(total / (1000 * 60 * 60 * 24))
return {
total,
ms,
days,
hours,
minutes,
seconds,
}
}
let togglePair = [cd0, cd1]
fore.value = localStorage.Foreground || fore.value
back.value = localStorage.Background || back.value
function initializeClock(id, goals) {
let oldText = "";
let olderText = "";
const r = () => {
const endtime = goals[selector.value]
const t = getTimeRemaining(endtime)
document.body.style.backgroundColor = Background
document.body.style.color = Foreground
Object.assign(localStorage, { Foreground, Background })
const text = `[${t.hours}:${t.minutes
.toString()
.padStart(2, 0)}:${t.seconds.toString().padStart(2, 0)}]`
.replace("[0:", "[")
.replace("[0:", "[")
.replace("[0", "[")
if (text != oldText) {
[cd1, cd0] = [cd0, cd1]
cd0.style.opacity = 1
cd1.dataset.active = 1
cd1.style.opacity = 0
delete cd0.dataset.active
olderText = text
}
// cd1.textContent = oldText
cd0.textContent = text
oldText = text
if (t.total <= 0) {
cd0.textContent = cd0.textContent
.replace(/:-(?=\d\d)/, ":")
if (Math.floor(Date.now() / 500) % 2) {
document.body.style.backgroundColor = Foreground
document.body.style.color = Background
}
}
requestAnimationFrame(r)
}
r()
}
goals = {}
selector = document.getElementById("countdowns")
function setGoal(name, h = 12, m = 0, s = 0) {
let goal = new Date()
goal.setHours(h)
goal.setMinutes(m)
goal.setSeconds(s)
goal.name = name
goals[name] = goal
const opt = document.createElement("option")
opt.textContent = name
selector.add(opt)
}
function fixGoals() {
let goal
for (goal in Object.keys(goals)) {
let newGoal = new Date()
newGoal.setHours(goal.getHours())
newGoal.setMinutes(goal.getMinutes())
newGoal.setSeconds(goal.getSeconds())
newGoal.setMilliseconds(goal.getMilliseconds())
}
}
function tryEgg(e) {
if (!EggAvailable) return
e.preventDefault()
e.stopPropagation()
open("/chat")
return false
}
setGoal("LUNCH", 12, 10)
setGoal("MIDAY")
setGoal("DISMS", 13, 50)
setGoal("DONUT", 0)
initializeClock("countdown", goals)
</script>