kontakt: [email protected]
Widżet:Orgonity: Różnice pomiędzy wersjami
Przejdź do nawigacji
Przejdź do wyszukiwania
imported>Sługa szatana test |
imported>Sługa szatana mNie podano opisu zmian |
||
(Nie pokazano 23 pośrednich wersji utworzonych przez tego samego użytkownika) | |||
Linia 1: | Linia 1: | ||
<includeonly><script type="text/javascript"> | <includeonly><div id="orgonity"></div><script type="text/javascript"> | ||
let timer; | |||
</script></includeonly> | let format = arr => { | ||
let wynik = []; | |||
let sec = interval / 1000; | |||
let plural = (value, a, b, c) => { | |||
return {"one": a, "other": b, "few": b, "many": c || b}[new Intl.PluralRules("en-us").select(value)]; | |||
} | |||
let [days, hours, minutes, seconds] = arr; | |||
if (days > 0) { | |||
wynik.push(days + plural(days, " day", " days")); | |||
} | |||
if (hours > 0) { | |||
wynik.push(hours + plural(hours, " hour", " hours")); | |||
} | |||
if (minutes > 0) { | |||
wynik.push(minutes + plural(minutes, " minute", " minutes")); | |||
} | |||
if (seconds > 0) { | |||
wynik.push(seconds + plural(seconds, " second", " seconds")); | |||
} | |||
return wynik.join(", "); | |||
} | |||
let interval = i => { | |||
let sec = i / 1000; | |||
let days = Math.floor(sec / 86400); | |||
let hours = Math.floor(sec % 86400 / 3600); | |||
let minutes = Math.floor(sec % 3600 / 60); | |||
let seconds = Math.floor(sec % 60); | |||
return [days, hours, minutes, seconds]; | |||
} | |||
let update = () => { | |||
if (orgonity()) { | |||
jupi(document.getElementById("orgonity")); | |||
clearInterval(timer); | |||
return; | |||
} | |||
let a = new Date(); | |||
a.setHours(0); | |||
a.setMinutes(0); | |||
a.setSeconds(0); | |||
a.setMilliseconds(0); | |||
let b = new Date(); | |||
// zajebane ze stackoverflow | |||
a.setDate(a.getDate() + (12 - b.getDay()) % 7 + 1); | |||
let r = interval(Math.abs(b - a)); | |||
let formatted = format(r); | |||
let orgonit = document.getElementById("orgonity"); | |||
orgonit.innerText = formatted; | |||
}; | |||
let orgonity = () => { | |||
let now = new Date(); | |||
return now.getDay() == 6 && now.getHours() < 4; | |||
} | |||
let jupi = el => { | |||
el.classList.add("pulse"); | |||
el.style.color = "green"; | |||
el.style.fontSize = "1.25em"; | |||
el.style.fontWeight = "bold"; | |||
el.innerText = "ORGONITY JUPI"; | |||
} | |||
if (orgonity()) { | |||
jupi(document.getElementById("orgonity")); | |||
} else { | |||
update(); | |||
timer = setInterval(update, 1000); | |||
console.debug(timer); | |||
} | |||
</script><style>.pulse { | |||
animation-name: pulse; | |||
animation-iteration-count: infinite; | |||
animation-duration: 1s; | |||
} | |||
@keyframes pulse { | |||
0% { | |||
opacity: 1; | |||
} | |||
50% { | |||
opacity: 0; | |||
} | |||
100% { | |||
opacity: 1; | |||
} | |||
} | |||
</style></includeonly> |