Widżet:Orgonity: Różnice pomiędzy wersjami

Z ChanWiki
Przejdź do nawigacji Przejdź do wyszukiwania
imported>Sługa szatana
mNie podano opisu zmian
imported>Sługa szatana
mNie podano opisu zmian
 
(Nie pokazano 22 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 format = interval => {
    let timer;
         console.debug(interval);
     let format = arr => {
         return "";
        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 a = new Date();
     let interval = i => {
    a.setHours(0);
        let sec = i / 1000;
    a.setMinutes(0);
 
    a.setSeconds(0);
        let days    = Math.floor(sec / 86400);
    a.setMilliseconds(0);
        let hours  = Math.floor(sec % 86400 / 3600);
    a.setDate(a.getDate() + (13 - a.getDay()) % 7);
        let minutes = Math.floor(sec % 3600 / 60);
     let b = new Date();
        let seconds = Math.floor(sec % 60);
     console.log(format(Math.abs(a - b));
        return [days, hours, minutes, seconds];
</script></includeonly>
    }
    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>

Aktualna wersja na dzień 04:31, 12 gru 2021