-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
191 lines (151 loc) · 4.71 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
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
//DOIS ELEVADOS
function addWeeks (weeks) {
var date = new Date(2017, 08, 13);
for(let i= 0; i<weeks;i++){
date.setDate(date.getDate() + 7);
}
return date;
}
function nextWeek(num){
let weeks = 1
for(let i = 0; i<num;i++){
weeks *=2
}
return addWeeks(weeks)
}
function pupolate2(){
let data = new Date(2017, 08, 13)
let datas = [data]
for(let i =0;i<15;i++){
datas.push(nextWeek(i))
}
return datas
}
//ANIVERSARIOS
function addYears(data,num){
var year = data.getFullYear();
var month = data.getMonth();
var day = data.getDate();
return new Date(year + num, month, day)
}
function pupolateKid(){
let dKid = new Date(2017, 4, 16)
let datas = []
for(let i= 0; i<15; i++){
datas.push(addYears(dKid, i))
}
return datas
}
function pupolateMistolim(){
let dMis = new Date(2017, 06, 30)
let datas = []
for(let i= 0; i<15; i++){
datas.push(addYears(dMis, i))
}
return datas
}
//Orders
function turnToObj(array,string,def){
let obj = []
let i = -1
array.forEach( function(elem){
let now = new Date()
if(string ==="twos"){
if(now - elem < 0){
obj.push({ type: def, num:i, css:string ,date: elem, next:"nextEvent"})
i++
}
else{
obj.push({ type: def, num:i, css:string ,date: elem, next:""})
i++
}
}
else{
if(now-elem < 0){
obj.push({ type: def, css:string ,date: elem, next:"nextEvent"})
}
else{
obj.push({ type: def, css:string ,date: elem, next:""})
}
}
})
return obj
}
function findSmall(date1, date2){
if(date1 - date2 < 0){
return 0
}
else{
return 1
}
}
function orderMerge(array1, array2){
let size = array1.length +array2.length
let array = []
let ans
while(size>0){
if(array1[0] === undefined){
array.push(array2[0])
array2.shift()
}
else if(array2[0] === undefined){
array.push(array1[0])
array1.shift()
}
else{
ans = findSmall(array1[0].date,array2[0].date)
if(ans === 0){
array.push(array1[0])
array1.shift()
}
else{
array.push(array2[0])
array2.shift()
}
}
size = array1.length + array2.length
}
return array
}
function extraObj(){
let array = []
array.push({ type: '<p>Primeiro jantar e</p><p> primeira foto</p><span style="color: #E8E8D1;"> <i class="fas fa-camera"></i></span>', css:"extra foto1" ,date: new Date(2017,2,1), next:""})
array.push({ type: '<p>A kid e o mistolas</p><p> são amigos no facebook</p> <span tyle="font-size: 2em; style="color: #E8E8D1;"> <i class="fab fa-user-friends"> </i> </span>', css:"extra" ,date: new Date(2017,5,18), next:""})
array.push({ type: 'Primeiro beijo <span style="color: #E8E8D1;"> <i class="fas fa-kiss-wink-heart"></i></span>', css:"extra" ,date: new Date(2017,6,26), next:""})
array.push({ type: "KID A TUNANTE", css:"extra foto2" ,date: new Date(2018,3,20), next:""})
array.push({ type: "MISTOLIM A TUNO", css:"extra foto3" ,date: new Date(2018,7,11), next:""})
return array
}
function order(kid, mistolim,twos){
let kidObj = turnToObj(kid,'kid', 'Kidolas faz anos <span style="color: #E8E8D1;"> <i class="fas fa-birthday-cake"></i></span>')
let mistolimObj = turnToObj(mistolim,'mistolim', 'Mistolas faz anos <span style="color: #E8E8D1;"> <i class="fas fa-birthday-cake"></i></span>')
let twosObj = turnToObj(twos,'twos', "Exponenciais de fofuras")
let extra = extraObj()
let array = orderMerge(kidObj, mistolimObj)
array = orderMerge(array, twosObj)
array = orderMerge(array,extra)
return array
}
//PUPOLATES
let kid = pupolateKid()
let mistolim = pupolateMistolim()
let twos = pupolate2()
let orders = order(kid,mistolim,twos)
orders.forEach(function(elem){
if(elem.num>=0){
document.write( `
<div>
<li class="flex-item ${elem.next} ${elem.css}">${elem.type}<p>2^${elem.num} </p></li>
<h3 style="text-align: center"> ${elem.date.getDate()}/${elem.date.getMonth()+1}/${elem.date.getFullYear()} </h3>
</div>
`)
}
else{
document.write( `
<div>
<li class="flex-item ${elem.next} ${elem.css}">${elem.type} </li>
<h3 style="text-align: center"> ${elem.date.getDate()}/${elem.date.getMonth()+1}/${elem.date.getFullYear()} </h3>
</div>
`)
}
})