-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
213 lines (191 loc) · 9.38 KB
/
app.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
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
const cityDiv = document.querySelector(".currentCity")
const cityNamePar = document.querySelector(".cityName")
const cityInfoDiv = document.querySelector(".cityInfo")
const hourlyBtn = document.querySelector(".hourlyButton")
const weeklyBtn = document.querySelector(".weeklyButton")
const mainImg = document.querySelector("#mainImage")
const temperatureDiv = document.querySelector(".currentTemperature");
const weatherImg = document.querySelector(".weatherImage")
const cityTemPar = document.querySelector("#tempDisp")
const tempTypeBtm = document.querySelector(".temperatureType")
const searchDiv = document.querySelector(".searchCity")
const cityInp = document.querySelector(".cityInput")
const foreCastDiv = document.querySelector(".foreCast")
const hOne = document.querySelector(".hOne")
const imageOne = document.querySelector("#imageOne")
const extraOne = document.querySelector(".extraOne")
const hTwo = document.querySelector(".hTwo")
const extraTwo = document.querySelector(".extraTwo")
const imageTwo = document.querySelector("#imageTwo")
const hThree = document.querySelector(".hThree")
const extraThree = document.querySelector(".extraThree")
const imageThree = document.querySelector("#imageThree")
const currentForecast = document.querySelector(".currentForecast")
const currentExtra = document.querySelector(".currentExtra")
const imageFour = document.querySelector("#currentImage")
const hFive = document.querySelector(".hFive")
const imageFive = document.querySelector("#imageFive")
const extraFive = document.querySelector(".extraFive")
const hSix = document.querySelector(".hSix")
const extraSix = document.querySelector(".extraSix")
const imageSix = document.querySelector("#imageSix")
const hSeven = document.querySelector(".hSeven")
const imageSeven = document.querySelector("#imageSeven")
const extraSeven = document.querySelector(".extraSeven")
const timeDisplay = document.querySelector("#time")
const dateDisplay = document.querySelector(".date")
const citiesUl = document.querySelector(".citiesListV")
const minTempDisp = document.querySelector(".minTemp")
const maxTempDisp = document.querySelector(".maxTemp")
const percDisp = document.querySelector(".precipitation")
const windSpeedDIsp = document.querySelector(".wind-speed")
const weatherCondition = document.querySelector(".weatherCondition")
const windImg = document.querySelector("#windImage")
const weatherInfoDiv = document.querySelector(".weatherInfo")
const bkgImage = document.querySelector("#bkgImg")
const loadingAni = document.querySelectorAll(".loadingAnimation")
const currentLocBtn = document.querySelector(".currentLocation");
const foreCastDivOne = document.querySelector(".foreCastDiv");
const tempsAndModesDiv = document.querySelector(".tempsAndModes");
class WeatherConditions {
constructor(tod) {
this.conditions = [
{
code: [0, 1],
img: `https://github.com/basmilius/weather-icons/raw/dev/production/fill/svg/clear-${tod}.svg`,
bimg: `./imgs/backgorund3.jpg`,
text: `There's Clear Skies`
},
{
code: [2],
img: `https://github.com/basmilius/weather-icons/raw/dev/production/fill/svg/partly-cloudy-${tod}.svg`,
bimg: `./imgs/backgorund3.jpg`,
text: `It's Partly Clody`
},
{
code: [3],
img: `https://github.com/basmilius/weather-icons/raw/dev/production/fill/svg/overcast-${tod}.svg`,
bimg: `./imgs/backgorund2.jpg`,
text: `The Sky is Overcast`
},
{
code: [45, 48],
img: `https://github.com/basmilius/weather-icons/raw/dev/production/fill/svg/fog-${tod}.svg`,
bimg: `./imgs/backgorund5.jpg`,
text: `There's Foggy weather`
},
{
code: [51, 53, 55],
img: `https://github.com/basmilius/weather-icons/raw/dev/production/fill/svg/partly-cloudy-${tod}-drizzle.svg`,
bimg: `./imgs/backgorund1.jpg`,
text: `A moderade Drizzle`
},
{
code: [56],
img: `https://github.com/basmilius/weather-icons/raw/dev/production/fill/svg/partly-cloudy-${tod}-sleet.svg`,
bimg: `./imgs/backgorund1.jpg`,
text: `A Freezing Dizzle`
},
{
code: [57],
img: `https://github.com/basmilius/weather-icons/raw/dev/production/fill/svg/partly-cloudy-${tod}-hail.svg`,
bimg: `./imgs/backgorund1.jpg`,
text: `There's Hail`
},
{
code: [61, 63, 65, 66, 67, 80, 81, 82],
img: `https://github.com/basmilius/weather-icons/raw/dev/production/fill/svg/partly-cloudy-${tod}-rain.svg`,
bimg: `./imgs/backgorund1.jpg`,
text: `It's Rainy`
},
{
code: [71, 73, 75, 77, 85, 86],
img: `https://github.com/basmilius/weather-icons/raw/dev/production/fill/svg/partly-cloudy-${tod}-snow.svg`,
bimg: `./imgs/backgorund6.jpg`,
text: `It's Snowy`
},
{
code: [95],
img: `https://github.com/basmilius/weather-icons/raw/dev/production/fill/svg/thunderstorms-${tod}.svg`,
bimg: `./imgs/backgorund4.jpg`,
text: `There's a Thunderstorm`
},
{
code: [96, 99],
img: `https://github.com/basmilius/weather-icons/raw/dev/production/fill/svg/thunderstorms-${tod}-rain.svg`,
bimg: `./imgs/backgorund4.jpg`,
text: `Thunderstorm with Hail`
}
]
}
}
const WindConditions = [
{ maxSpeed: Infinity, minSpeed: 68, img: "https://github.com/basmilius/weather-icons/raw/dev/production/fill/svg/wind-beaufort-12.svg" },
{ maxSpeed: 67, minSpeed: 58, img: "https://github.com/basmilius/weather-icons/raw/dev/production/fill/svg/wind-beaufort-11.svg" },
{ maxSpeed: 58, minSpeed: 50, img: "https://github.com/basmilius/weather-icons/raw/dev/production/fill/svg/wind-beaufort-10.svg" },
{ maxSpeed: 50, minSpeed: 42, img: "https://github.com/basmilius/weather-icons/raw/dev/production/fill/svg/wind-beaufort-9.svg" },
{ maxSpeed: 42, minSpeed: 34, img: "https://github.com/basmilius/weather-icons/raw/dev/production/fill/svg/wind-beaufort-8.svg" },
{ maxSpeed: 34, minSpeed: 27, img: "https://github.com/basmilius/weather-icons/raw/dev/production/fill/svg/wind-beaufort-7.svg" },
{ maxSpeed: 27, minSpeed: 21, img: "https://github.com/basmilius/weather-icons/raw/dev/production/fill/svg/wind-beaufort-6.svg" },
{ maxSpeed: 21, minSpeed: 15, img: "https://github.com/basmilius/weather-icons/raw/dev/production/fill/svg/wind-beaufort-5.svg" },
{ maxSpeed: 15, minSpeed: 9, img: "https://github.com/basmilius/weather-icons/raw/dev/production/fill/svg/wind-beaufort-4.svg" },
{ maxSpeed: 9, minSpeed: 5, img: "https://github.com/basmilius/weather-icons/raw/dev/production/fill/svg/wind-beaufort-3.svg" },
{ maxSpeed: 5, minSpeed: 2, img: "https://github.com/basmilius/weather-icons/raw/dev/production/fill/svg/wind-beaufort-2.svg" },
{ maxSpeed: 2, minSpeed: 1, img: "https://github.com/basmilius/weather-icons/raw/dev/production/fill/svg/wind-beaufort-1.svg" },
{ maxSpeed: 0, minSpeed: 0, img: "https://github.com/basmilius/weather-icons/raw/dev/production/fill/svg/wind-beaufort-0.svg" }
]
const forecastElements = [hOne, hTwo, hThree, currentForecast, hFive, hSix, hSeven, imageOne, imageTwo, imageThree, imageFour, imageFive, imageSix, imageSeven, extraOne, extraTwo, extraThree, currentExtra, extraFive, extraSix, extraSeven]
let newSuperArray = [forecastElements.filter((v, index) => index >= 0 && index < 7), forecastElements.filter((v, index) => index >= 7 && index < 14), forecastElements.filter((v, index) => index >= 14 && index < 21)]
let currentCityCords = {
latitude: 41.99646,
longitude: 21.43141
}
let currentCity;
let newDate;
let intervalId;
let sunrise;
let sunset;
let firstPress = true;
let weeklyPressed = false
hourlyBtn.classList.add("show-before");
let unit = "°C"
let uni = "&"
let speedUnit = "km/h"
let timeOfDay = "day"
function getTime(timezone) {
let abrv = "th"
newDate = new Date().toLocaleString("en-US", { timeZone: timezone });
const hours = new Date(newDate).getHours()
const minutes = new Date(newDate).getMinutes()
const seconds = new Date(newDate).getSeconds()
const month = new Date(newDate).toLocaleString('default', { month: 'long' });
const day = new Date(newDate).getDate()
switch (day % 10) {
case 1:
abrv = "st"
break;
case 2:
abrv = "nd"
break;
case 3:
abrv = "rd"
break;
default:
abrv = "th"
}
timeDisplay.innerHTML = `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
dateDisplay.innerHTML = `${ month } ${ day }${ abrv }`;
clearInterval(intervalId);
intervalId = setInterval(() => {
getTime(timezone);
}, 1000);
}
const makeCall = async url => {
try {
const response = await fetch(url);
return await response.json();
} catch (error) {
console.log('The request failed!');
return error
}
}