-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
112 lines (102 loc) · 3.71 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
//to-do list
let button = document.querySelector(".task button");
let input = document.querySelector(".task input");
let ul = document.querySelector("ul");
let h3 = document.querySelector("h4");
let count = 1;
button.addEventListener("click", function () {
if (input.value != "") {
count++;
h3.innerText = `TOTAL TASK : ${count}`;
let li = document.createElement("li");
ul.appendChild(li);
let div = document.createElement("div");
div.innerHTML = ` <div>
<button class="notify"><span class="material-symbols-outlined"
style="font-size: 20px;font-weight: 700; margin: 0px; padding: 0px;">
notifications_active
</span></button>
<h2>${input.value}</h2>
</div>
<button>Done</button>`;
div.setAttribute("class", "task1");
li.appendChild(div);
let a = Math.floor(Math.random() * 155 + 100);
let b = Math.floor(Math.random() * 155 + 100);
let c = Math.floor(Math.random() * 155 + 100);
div.style.backgroundColor = `rgb(${a},${b},${c})`;
input.value = "";
}
});
ul.addEventListener("click", function (event) {
if (event.target.innerText == "Done") {
ul.removeChild(event.target.parentElement.parentElement);
count--;
h3.innerText = `TOTAL TASK : ${count}`;
}
});
//date time
let h2 = document.querySelector(".date");
let h = document.querySelector(".time");
let arr = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
const date = new Date();
h2.innerText = `${arr[date.getDay()]}, ${date.getDate()}-${date.getMonth()}-${date.getFullYear()} `;
h.innerText = `Time ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
setInterval(() => {
const date = new Date();
h.innerText = `Time ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
}, 1000);
//Alarm
ul.addEventListener("click", function (event) {
if (event.target.innerText == "notifications_active") {
let time=prompt("Enter Time : hh:mm:ss");
const date2 = new Date();
let nexthour=Number(time.substring(0,2))-date2.getHours();
let nextminit=Number(time.substring(3,5))-date2.getMinutes();
let nextsec=Number(time.substring(6,8))-date2.getSeconds();
let delay=(nexthour*3600+nextminit*60+nextsec)*1000
setTimeout(async function(){
event.target.parentElement.parentElement.parentElement.style.backgroundColor="red";
let audio=new Audio("asset/Ringtones.mp3");
await audio.play();
alert(`Its Time to ${event.target.parentElement.parentElement.innerText}`);
audio.pause();
},delay);
}
});
//Weather API
let place = document.querySelector(".weather h3");
let temp = document.querySelector(".temp");
let img = document.querySelector(".weather-temp img");
let weat = document.querySelector(".weather h2");
let p = document.querySelector(".weather p");
let get = document.querySelector(".get");
let change = document.getElementById("search");
const url = "http://api.weatherapi.com/v1/current.json?key=dd35b36d343049bdad990057232009&q=";
let q = "jalpaiguri";
async function Weather(q) {
try {
let res = await axios(url + q);
let data = res.data.current;
place.innerText = q;
temp.innerHTML = `${data.feelslike_c}°C`;
img.src = `https:${data.condition.icon}`;
weat.innerText = data.condition.text;
p.innerHTML = `pressure: ${data.pressure_mb} millibars
<br>
Humidity: ${data.humidity} %
<br>
Wind: ${data.wind_dir} , ${data.wind_kph} kph`;
}
catch (err) {
console.log("Invalid City");
}
}
Weather(q);
get.addEventListener("click",()=>{
if(change.value!=""){
q=change.value;
Weather(q);
q="";
}
});