-
Notifications
You must be signed in to change notification settings - Fork 0
/
kw.js
65 lines (55 loc) · 3.57 KB
/
kw.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
// Kw’s JS
// Copyright © 2014-2021, Chris Warrick.
function updateCsText() {
csText = csDict[colorScheme][document.querySelector('html').lang];
}
var csDict={'dark':{'pl':'Tryb Jasny','en':'Light Mode'},'light':{'pl':'Tryb Ciemny','en':'Dark Mode'},'loading':{'pl':'Zmieniam schemat kolorów, proszę czekać…','en':'Changing color scheme, please wait…'}};
var csText;
updateCsText();
function changeColors() {
var csOther = {'dark': 'light', 'light': 'dark'};
colorScheme = csOther[colorScheme];
var style = document.createElement('style');
style.id = "color-changer-loading-style";
style.innerText = "#color-changer-loading-box{font-family:'Source Sans Pro',sans-serif;font-size:16px;line-height:40px;background:#6c757d;color:#fff;position:fixed;left:50%;top:50%;margin-top:-20px;margin-left:-200px;height:40px;width:400px;border-radius:4px;border:1px solid #0ad;box-shadow:0px 0px 20px #0ad;transition:all .5s ease;text-align:center;opacity:1;}*{box-sizing:border-box;transition:background 1.5s ease,color 0.25s linear}@media(max-width:550px){#color-changer-loading-box{left:1%;margin-left:0;width:98%;}}</style>";
document.head.append(style);
var loadbox = document.createElement('div');
loadbox.id = "color-changer-loading-box";
loadbox.innerText = csDict['loading'][document.querySelector('html').lang];
document.body.append(loadbox);
setTimeout(function() {
document.cookie = 'colorScheme=' + colorScheme + '; expires=17-Jan-2038 03:14:07 GMT; path=/';
if (colorScheme === 'light') {
document.querySelector("#kw-all-css").href = 'https://chriswarrick.com/assets/css/all.css?v=20230115';
} else {
document.querySelector("#kw-all-css").href = 'https://chriswarrick.com/assets/css/all-dark.css?v=20230115';
}
updateCsText();
document.querySelector("#color-changer-text").innerText = csText;
setTimeout(function() { loadbox.style = 'opacity:0'; }, 5000);
setTimeout(function() { loadbox.remove(); style.remove(); }, 6000);
}, 250);
return false;
}
function onLoaded() {
document.querySelector("#color-changer-text").innerText = csText;
if (document.cookie.indexOf('kw_cookies=2') == -1) {
if (document.querySelector('html').lang == 'pl') {
document.querySelector("#cookiebox").innerHtml = '<div class="alert alert-primary fade show" role="alert" id="cookiealert">Ta strona używa ciasteczek. <a href="/pl/privacy/" class="alert-link">Dowiedz się więcej.</a> <button type="button" class="close" data-dismiss="alert">× Rozumiem</button></div>';
} else {
document.querySelector("#cookiebox").innerHtml = '<div class="alert alert-primary fade show" role="alert" id="cookiealert">This site uses cookies. <a href="/privacy/" class="alert-link">Read more.</a> <button type="button" class="close" data-dismiss="alert">× Got it</button></div>';
}
}
$('#cookiealert').on('closed.bs.alert', function () {
// One second before the year 2038 bug.
document.cookie = 'kw_cookies=2; expires=17-Jan-2038 03:14:07 GMT; path=/';
});
document.querySelector("#color-changer-btn").addEventListener('click', changeColors);
document.querySelector("#color-changer-mobile").addEventListener('click', changeColors);
var sc = document.querySelector("#snackbar-container");
if (sc !== null) {
setTimeout(function() { sc.classList.add("snackbar-container-hidden"); }, 5000);
setTimeout(function() { sc.remove() }, 5500);
}
}
document.addEventListener('DOMContentLoaded', onLoaded, false);