-
Notifications
You must be signed in to change notification settings - Fork 1
/
SCRIPT.js
108 lines (86 loc) · 3.22 KB
/
SCRIPT.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
let meusItems = [];
window.onload = () => {
if(!localStorage.getItem("tudoLista")) {
localStorage.setItem("tudoLista", JSON.stringify([]));
} else {
meusItems =JSON.parse(localStorage.getItem("tudoLista"));
meusItems.forEach(item => displayItems(item));
}
}
function atualizaRelogio() {
var momentoAtual = new Date();
var vhora = momentoAtual.getHours();
var vminuto = momentoAtual.getMinutes();
var vsegundo = momentoAtual.getSeconds();
var vdia = momentoAtual.getDate();
var vmes = momentoAtual.getMonth() + 1;
var vano = momentoAtual.getFullYear();
if (vdia < 10) { vdia = "0" + vdia; }
if (vmes < 10) { vmes = "0" + vmes; }
if (vhora < 10) { vhora = "0" + vhora; }
if (vminuto < 10) { vminuto = "0" + vminuto; }
dataFormat = vdia + " / " + vmes + " / " + vano;
horaFormat = vhora + " : " + vminuto;
document.getElementById("data").textContent = dataFormat;
document.getElementById("hora").textContent = horaFormat;
setTimeout("atualizaRelogio()", 1000);
};
atualizaRelogio();
function criarItem(conteudo){
if (conteudo.length > 0){
//pega o elemento pai
var ulpai = document.getElementById("para-fazer");
//cria um novo elemento com tag "li"
var novoel = document.createElement("li");
//adiciona o conteudo
novoel.textContent = conteudo;
//adiciona o click pra remover
novoel.addEventListener("click", removersi);
//atualiza a lista pro localStorage
meusItems.push(novoel.textContent);
//adiciona animaçao
novoel.classList.add("adicionando");
//adiciona o "li" para o elemento pai "ul"
ulpai.appendChild(novoel);
//atualiza o localStorage
localStorage.setItem("tudoLista", JSON.stringify(meusItems));
}
}
var input = document.getElementById('aitem');
input.addEventListener("keydown", (e) =>{
if(e.keyCode == 13){
criarItem(input.value);
input.value = "";
}
})
var itens = document.querySelectorAll("li");
itens.forEach(item=>item.addEventListener("click", removersi));
function removersi(event){
// var titulo = event.target.textContent
var ulpai = document.getElementById("para-fazer");
var el = event.target.textContent;
var elemento = event.target;
console.log(elemento);
elemento.classList.remove("adicionando");
elemento.classList.add("excluindo");
meusItems = meusItems.filter((item) => item !== el);
localStorage.setItem("tudoLista", JSON.stringify(meusItems));
setTimeout(() => {
elemento.remove();
}, 200);
}
var pesquisar = document.getElementById('pesquisar');
pesquisar.addEventListener("keydown", (e) =>{
if(e.keyCode == 13){
var termos = pesquisar.value;
window.open(`https://www.google.com/search?q=${termos}`);
pesquisar.value = "";
}
})
function displayItems(conteudo){
let ulpai = document.getElementById("para-fazer");
var novoel = document.createElement("li");
novoel.textContent = conteudo;
novoel.addEventListener("click", removersi);
ulpai.appendChild(novoel);
}