-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathmain.js
More file actions
181 lines (146 loc) · 6.01 KB
/
main.js
File metadata and controls
181 lines (146 loc) · 6.01 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
//Dropdown menu
function showTime() {
d = new Date(); //Getting the local date object
countryName = document.getElementById('country-name')
utc = d.getTime() + d.getTimezoneOffset() * 60000; //converting the time to gmt and in miliseconds for easier conversion of time for different countries
checkDropdown = document.getElementById("list").value; // getting the value of the selected country
modalBg = document.getElementsByClassName('modal-content');
var session = "AM";
if (checkDropdown == "india") {
nd = new Date(utc + 3600000 * 5.5); // create new object of the date according to chosen country
countryName.innerHTML = 'India';
} else if (checkDropdown == "california") {
countryName.innerHTML = 'California';
nd = new Date(utc + 3600000 * -7);
} else if (checkDropdown == "newYork") {
countryName.innerHTML = 'New York';
nd = new Date(utc + 3600000 * -4);
} else if (checkDropdown == "japan") {
countryName.innerHTML = 'Japan';
nd = new Date(utc + 3600000 * 9);
} else if (checkDropdown == "uae") {
countryName.innerHTML = 'UAE';
nd = new Date(utc + 3600000 * 4);
} else if (checkDropdown == "moscow") {
countryName.innerHTML = 'Moscow';
nd = new Date(utc + 3600000 * 3);
} else if (checkDropdown == "france") {
countryName.innerHTML = 'France';
nd = new Date(utc + 3600000 * 2);
} else if (checkDropdown == "africa") {
countryName.innerHTML = 'Africa';
nd = new Date(utc + 3600000 * 2);
}else if (checkDropdown == "afghanistan"){
nd = new Date(utc + 3600000 * 4.5);
}else if (checkDropdown == "belgium"){
nd = new Date(utc + 3600000 * 1);
}else if (checkDropdown == "denmark"){
nd = new Date(utc + 3600000 * 1);
}else if (checkDropdown == "jamaica"){
nd = new Date(utc + 3600000 * -5);
}else if (checkDropdown == "china"){
nd = new Date(utc + 3600000 * 8);
}else if (checkDropdown == "southk"){
nd= new Date(utc +3600000 * 9);
countryName.innerHtML= ' South Korea';
}
// Changed the timming in 12 hours format
var res = nd.toLocaleString();
res = res.split(" ");
var ans = res[1].split(":");
if (ans[0] > 12) {
var t = parseInt(ans[0]) - 12;
ans[0] = t.toString();
session = "PM";
}
if (ans[0] == 0) {
ans[0] = "12";
}
res[1] = ans.join(":");
document.getElementById("clock").innerHTML = res[1] + " " + session;
setTimeout(showTime, 1000);
//If the current time is between 7 PM to 7AM UI changes to dark mode.
var ti = nd.toString();
ti = ti.split(" ");
var ri = ti[4].split(":");
if(ri[0]<=18 && ri[0]>7){
//Light Mode
var element = document.createElement("link");
element.setAttribute("rel", "stylesheet");
element.setAttribute("type", "text/css");
element.setAttribute("href", "css/light.css");
document.getElementsByTagName("head")[0].appendChild(element);
}else{
//Dark Mode
var element = document.createElement("link");
element.setAttribute("rel", "stylesheet");
element.setAttribute("type", "text/css");
element.setAttribute("href", "css/Style.css");
document.getElementsByTagName("head")[0].appendChild(element);
}
}
showTime();
//Scroll the list of countries
document.getElementById("list").addEventListener("scroll", scroll);
function scroll() {
document.getElementsByClassName("box").innerHTML = "Scrolled";
}
//Analog Clock
setInterval(setClock, 1000);
const IndiahourHand = document.querySelector("[india-hour-hand]");
const IndiaminuteHand = document.querySelector("[india-minute-hand]");
const IndiasecondHand = document.querySelector("[india-second-hand]");
const chicagohourHand = document.querySelector("[chicago-hour-hand]");
const chicagominuteHand = document.querySelector("[chicago-minute-hand]");
const chicagosecondHand = document.querySelector("[chicago-second-hand]");
const japanhourHand = document.querySelector("[japan-hour-hand]");
const japanminuteHand = document.querySelector("[japan-minute-hand]");
const japansecondHand = document.querySelector("[japan-second-hand]");
function setClock() {
const indiacurrentDate = new Date();
const indiasecondsRatio = indiacurrentDate.getSeconds() / 60;
const indiaminutesRatio = (indiasecondsRatio + indiacurrentDate.getMinutes()) / 60;
const indiahoursRatio = (indiaminutesRatio + indiacurrentDate.getHours()) / 12;
var utc = indiacurrentDate.getTime() + indiacurrentDate.getTimezoneOffset() * 60000;
const chicagoCurrentDate = new Date(utc + 3600000 * -5);
const chicagosecondsRatio = chicagoCurrentDate.getSeconds() / 60;
const chicagominutesRatio = (chicagosecondsRatio + chicagoCurrentDate.getMinutes()) / 60;
const chicagohoursRatio = (chicagominutesRatio + chicagoCurrentDate.getHours()) / 12;
const japanCurrentDate = new Date(utc + 3600000 * 9);
const japansecondsRatio = japanCurrentDate.getSeconds() / 60;
const japanminutesRatio = (japansecondsRatio + japanCurrentDate.getMinutes()) / 60;
const japanhoursRatio = (japanminutesRatio + japanCurrentDate.getHours()) / 12;
setRotation(IndiasecondHand, indiasecondsRatio);
setRotation(IndiaminuteHand, indiaminutesRatio);
setRotation(IndiahourHand, indiahoursRatio);
setRotation(chicagosecondHand, chicagosecondsRatio);
setRotation(chicagominuteHand, chicagominutesRatio);
setRotation(chicagohourHand, chicagohoursRatio);
setRotation(japansecondHand, japansecondsRatio);
setRotation(japanminuteHand, japanminutesRatio);
setRotation(japanhourHand, japanhoursRatio);
}
function setRotation(element, rotationRatio) {
element.style.setProperty("--rotation", rotationRatio * 360);
}
//FAQs section
$('.acc h3').click(function(){
$(this).next('.content').slideToggle();
$(this).parent().toggleClass('active');
$(this).parent().siblings().children('.content').slideUp();
$(this).parent().siblings().removeClass('active');
});
const btn = document.getElementById('list');
const modal = document.getElementById('modal');
const span = document.getElementsByClassName('close')[0];
span.onclick = function(){
modal.style.display = "none";
}
btn.onclick = function(){
modal.style.display = "block";
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}