-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.js
279 lines (242 loc) · 8.62 KB
/
index.js
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
// document.addEventListener('contextmenu', event => event.preventDefault())
var days = 0
var hours = 0
var minutes = 0
var weeks = 0
var d = new Date()
var year = d.getUTCFullYear()
var month = d.getUTCMonth()
var day = d.getUTCDate()
var hour = d.getUTCHours()
var minute = d.getUTCMinutes()
var second = d.getUTCSeconds()
var timezone = d.getTimezoneOffset()
if (timezone > 0) {
document.getElementById("timezone").innerHTML = timezone/-60 + "h"
document.getElementById("fake-hour").innerHTML = timezone/-60
} else if (timezone < 0) {
document.getElementById("timezone").innerHTML = "+" + timezone/-60 + "h"
document.getElementById("fake-hour").innerHTML = "+" + timezone/-60
} else {
document.getElementById("timezone").innerHTML = ""
document.getElementById("fake-hour").innerHTML = ""
}
Date.prototype.addHours = function(h) {
this.setTime(this.getTime() + (h*60*60*1000));
return this;
}
// var newYears = new Date(Date.UTC(2024, 0, 1, 0, 0, 0))
// var newYears = new Date(Date.UTC(2023, 0, 1, 0, 0, 0))
// var newYears = new Date(Date.UTC(2022, 11, 27, 0, 0, 0))
// newYears.addHours(timezone/60)
// document.getElementById("special-new-years").innerHTML = `<t:${newYears.getTime()/1000}:R>`
function getTimestampType() {
switch (document.getElementById("type").value) {
case "coutdown": return "R>"
case "hour-short": return "t>"
case "hour-long": return "T>"
case "date-short": return "d>"
case "date-long": return "D>"
case "date-time": return "f>"
case "date-week": return "F>"
}
return "R>"
}
function timestamp() {
var datum = new Date(Date.UTC(year, month, day + days + weeks*7, hour + hours, minute + minutes, second))
// return datum.getTime()/1000
document.getElementById("special").innerHTML = `<t:${datum.getTime()/1000}:${getTimestampType()}`
}
function timestampglobal() {
var global_year = document.getElementById("year").value
var global_month = document.getElementById("month").value-1 // edit here
var global_day = document.getElementById("day").value
var global_hour = document.getElementById("hour").value
var global_minute = document.getElementById("minute").value
var datum = new Date(Date.UTC(global_year, global_month, global_day, global_hour, global_minute, 0))
// return datum.getTime()/1000
document.getElementById("special").innerHTML = `<t:${datum.getTime()/1000}:${getTimestampType()}`
}
timestamp()
document.getElementById("year").addEventListener("onchange", (event) => timestampglobal);
document.getElementById("month").addEventListener("onchange", (event) => timestampglobal);
document.getElementById("day").addEventListener("onchange", (event) => timestampglobal);
document.getElementById("hour").addEventListener("onchange", (event) => timestampglobal);
document.getElementById("minute").addEventListener("onchange", (event) => timestampglobal);
function AdjustWeeks(amount) {
weeks += amount
document.getElementById("weeks").innerHTML = `${weeks} weeks`
timestamp()
}
function AdjustDays(amount) {
days += amount
document.getElementById("days").innerHTML = `${days} days`
timestamp()
}
function AdjustHours(amount) {
hours += amount
document.getElementById("hours").innerHTML = `${hours} hours`
timestamp()
}
function AdjustMinutes(amount) {
minutes += amount
document.getElementById("minutes").innerHTML = `${minutes} minutes`
timestamp()
}
function HandleMouseClick(event, adjustFunction)
{
event.preventDefault();
if (event.which == 3) {
adjustFunction(-1)
}
if (event.which == 1) {
adjustFunction(1)
}
return false;
}
function HandleWheel(event, adjustFunction)
{
event.preventDefault();
if (event.deltaY > 0) {
adjustFunction(-1)
}
if (event.deltaY < 0) {
adjustFunction(1)
}
return false;
}
document.getElementById("weeks").onmousedown = event => HandleMouseClick(event, AdjustWeeks)
document.getElementById("days").onmousedown = event => HandleMouseClick(event, AdjustDays)
document.getElementById("hours").onmousedown = event => HandleMouseClick(event, AdjustHours)
document.getElementById("minutes").onmousedown = event => HandleMouseClick(event, AdjustMinutes)
document.getElementById("weeks").onwheel = event => HandleWheel(event, AdjustWeeks)
document.getElementById("days").onwheel = event => HandleWheel(event, AdjustDays)
document.getElementById("hours").onwheel = event => HandleWheel(event, AdjustHours)
document.getElementById("minutes").onwheel = event => HandleWheel(event, AdjustMinutes)
document.getElementById("mode").onchange = function (e) {
var relative = document.querySelector(".relative")
var nonrelative = document.querySelector(".nonrelative")
if (document.getElementById("mode").value == "timeframe") {
relative.hidden = false
nonrelative.hidden = true
reset()
} else {
relative.hidden = true
nonrelative.hidden = false
reset()
}
reset()
}
document.querySelector("#type").onchange = function (e) {
timestamp()
// update example image
var example = document.querySelector("img")
switch (document.getElementById("type").value) {
case "coutdown": example.src = "timestamp examples/relative.png"; break;
case "hour-short": example.src = "timestamp examples/time.png"; break;
case "hour-long": example.src = "timestamp examples/long-time.png"; break;
case "date-short": example.src = "timestamp examples/date.png"; break;
case "date-long": example.src = "timestamp examples/long-date.png"; break;
case "date-time": example.src = "timestamp examples/date-time.png"; break;
case "date-week": example.src = "timestamp examples/date-weekday.png"; break;
}
}
//document.getElementByClass("reset").onmousedown = function(event) {
function reset() {
weeks = 0
document.getElementById("weeks").innerHTML = `${weeks} weeks`
minutes = 0
document.getElementById("minutes").innerHTML = `${minutes} minutes`
hours = 0
document.getElementById("hours").innerHTML = `${hours} hours`
days = 0
document.getElementById("days").innerHTML = `${days} days`
document.getElementById("year").value = d.getUTCFullYear()
document.getElementById("month").value = d.getUTCMonth() +1 //edit here
document.getElementById("day").value = d.getUTCDate()
document.getElementById("hour").value = d.getUTCHours()
document.getElementById("minute").value = d.getUTCMinutes()
timestamp()
}
function copy(copyable){
navigator.clipboard.writeText(htmlDecode(document.getElementById(copyable).innerHTML))
.then(() => {
let a = document.getElementById("copy-banner")
a.classList.add('show')
setTimeout(function() {
a.classList.remove('show')
}, 2000)
});
}
function htmlDecode(input) {
var doc = new DOMParser().parseFromString(input, "text/html");
return doc.documentElement.textContent;
}
setInterval( ()=>{
var relative = document.querySelector(".relative")
d = new Date()
year = d.getUTCFullYear()
month = d.getUTCMonth()
day = d.getUTCDate()
hour = d.getUTCHours()
minute = d.getUTCMinutes()
second = d.getUTCSeconds()
if (relative.hidden == false) {
timestamp()
}
}, 1000)
document.querySelector(".minus-week").onclick = function() {
AdjustWeeks(-1)
}
document.querySelector(".minus-day").onclick = function() {
AdjustDays(-1)
}
document.querySelector(".minus-hour").onclick = function() {
AdjustHours(-1)
}
document.querySelector(".minus-minute").onclick = function() {
AdjustMinutes(-1)
}
document.querySelector(".plus-week").onclick = function() {
AdjustWeeks(1)
}
document.querySelector(".plus-day").onclick = function() {
AdjustDays(1)
}
document.querySelector(".plus-hour").onclick = function() {
AdjustHours(1)
}
document.querySelector(".plus-minute").onclick = function() {
AdjustMinutes(1)
}
fetch("https://api.github.com/repos/Dot32IsCool/discord-timestamp-generator")
.then(response => response.json())
.then(data => {
console.log(data.stargazers_count)
document.querySelector(".stars").innerHTML = `${data.stargazers_count} Stars`
})
fetch("https://discord.com/api/guilds/922185010205822976/widget.json")
.then(response => response.json())
.then(data => {
console.log(data.presence_count)
document.querySelector(".members").innerHTML = `${data.presence_count} Online`
// Show offline if bot is offline
// var members = data.members
// var online = 0
// for (var i = 0; i < members.length; i++) {
// var member = members[i]
// if (member.username == "Timer Bot") {
// console.log("Found timer bot")
// if (member.status == "online") {
// online = 1
// } else {
// online = 0
// }
// }
// }
// if (online == 0) {
// var el = document.querySelector(".server-count")
// el.innerHTML = "Offline"
// el.style.backgroundColor = "#808080"
// }
})