Welcome to mirror list, hosted at ThFree Co, Russian Federation.

less.js « js « assets - github.com/4ever9/less.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3221f4adb562562e5df38efb17986ac1440bed24 (plain)
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
const $btnDark = document.getElementById('btn-dark')
const $body = document.getElementsByTagName('body')
$btnDark.addEventListener('click', e => {
    e.preventDefault()
    $body[0].classList.toggle('dark')
    if (getCookie('dark') === "") {
        setCookie('dark', 'true', 7 * 24 * 60 * 60)
    } else {
        removeCookie('dark')
    }
})

if (getCookie('dark') === 'true') {
    $body[0].classList.add('dark')
}

function setCookie(key, value, second) {
    let d = new Date();
    d.setTime(d.getTime() + (second * 1000));
    let expires = "expires=" + d.toGMTString();
    document.cookie = key + "=" + value + "; " + expires + "; path=/";
}

function removeCookie(key) {
    let d = new Date();
    d.setTime(d.getTime() - 1);
    let expires = "expires=" + d.toGMTString();
    document.cookie = key + "=;" + expires + "; path=/";
}

function getCookie(key) {
    let name = key + "=";
    let ca = document.cookie.split(';');
    for (let i = 0; i < ca.length; i++) {
        let c = ca[i].trim();
        if (c.indexOf(name) === 0) return c.substring(name.length, c.length);
    }

    return "";
}