-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
97 lines (68 loc) · 3.36 KB
/
main.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//................................................................................//
// All logics //
//.................................................................................//
//........................................................Working with dark mode..............................................................//
//Cheking if website already in dark mode or not.
if(localStorage.getItem("dark_mode")) {
let get_dark_current_status = localStorage.getItem("dark_mode");
if(get_dark_current_status === "true") {
document.querySelector("html").classList.add("dark");
document.querySelector("#light_mode").classList.remove("hidden");
}
else {
document.querySelector("html").classList.remove("dark");
document.querySelector("#dark_mode").classList.remove("hidden");
}
}
//If user is new then by default light mode will activate.
else {
document.querySelector("#dark_mode").classList.remove("hidden");
}
//Cheking if dark mode id exist in the current webpage.
if(document.querySelector("#dark_mode")) {
let dark_mode = document.querySelector("#dark_mode");
dark_mode.addEventListener("click", ()=>{
turn_on_dark_mode();
})
}
//Cheking if light mode id exist in the current webpage.
if(document.querySelector("#light_mode")) {
let light_mode = document.querySelector("#light_mode");
light_mode.addEventListener("click", ()=>{
turn_on_light_mode();
})
}
//..............................................Working with dark mode part has been ended....................................................//
//................................................................................//
// All functions //
//.................................................................................//
//if user click on dark mode icon
function turn_on_dark_mode() {
localStorage.setItem("dark_mode", "true");
let current_status = localStorage.getItem("dark_mode");
if(current_status === "true") {
let light_mode = document.querySelector("#light_mode");
let dark_mode = document.querySelector("#dark_mode");
document.querySelector("html").classList.add("dark");
dark_mode.classList.add("hidden");
light_mode.classList.remove("hidden");
}
}
//If user click on light mode icon
function turn_on_light_mode() {
localStorage.setItem("dark_mode", "false");
let get_current_status = localStorage.getItem("#dark_mode");
if(get_current_status != "true") {
let get_dark_mode = document.querySelector("#dark_mode");
let get_light_mode = document.querySelector("#light_mode");
document.querySelector("html").classList.remove("dark");
get_dark_mode.classList.remove("hidden");
get_light_mode.classList.add("hidden");
}
}
var images = document.querySelectorAll('img');
images.forEach(function(img) {
img.addEventListener('click', function() {
window.open(this.src, '_blank');
});
});