This commit is contained in:
Piyush मिश्रः 2021-05-13 13:29:26 +05:30
parent 9333f398eb
commit 6587d92e5f
2 changed files with 26 additions and 2 deletions

View File

@ -273,6 +273,8 @@ function vayaktiList() {
function changeColor() { function changeColor() {
$('body').toggleClass('dark') $('body').toggleClass('dark')
if($('body').hasClass('dark')) setCookie('theme', 'dark', 30);
else setCookie('theme', 'light', 30);
$('#action_clip').addClass('is-hidden'); $('#action_clip').addClass('is-hidden');
} }

View File

@ -1,4 +1,4 @@
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches || getCookie('theme') == 'dark') {
$('body').toggleClass('dark'); $('body').toggleClass('dark');
} }
@ -47,3 +47,25 @@ $(document).ready(function() {
Images.setupImages(); Images.setupImages();
}); });
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}