-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
92 lines (70 loc) · 3.02 KB
/
index.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
const main = document.querySelector('main');
fetch('data.json')
.then(response => response.json())
.then(data => showContent(data[0]));
function showContent(datas){
const articleUser = document.createElement('article');
articleUser.classList.add('articleUser');
const divProfile = document.createElement('div');
divProfile.classList.add('divProfile')
const divOptions = document.createElement('div');
divOptions.classList.add('divOptions');
const imgProfile = document.createElement('img');
imgProfile.src = datas.imageProfile;
const h1Name = document.createElement('h1');
h1Name.textContent = datas.name;
const smallReport = document.createElement('small');
smallReport.textContent = "Report for";
divProfile.append(imgProfile, smallReport, h1Name);
const pDaily = document.createElement('p');
pDaily.textContent = 'Daily';
pDaily.style.color = "white";
const pWeekly = document.createElement('p');
pWeekly.textContent = 'Weekly';
const pMonthly = document.createElement('p');
pMonthly.textContent = 'Monthly';
divOptions.append(pDaily,pWeekly,pMonthly)
articleUser.append(divProfile, divOptions);
main.append(articleUser);
datas.activity.forEach(activity => {
const article = document.createElement('article');
const divTimer = document.createElement('div');
divTimer.classList.add('timeframesDiv');
const p = document.createElement('p');
p.textContent = activity.title;
const imgIcon = document.createElement('img');
imgIcon.src = './images/icon-ellipsis.svg'
article.style.backgroundColor = `${activity.color}`;
article.style.backgroundImage = `url(${activity.image})`;
const h2 = document.createElement('h2');
h2.textContent = `${activity.timeframes.daily.current}hrs`;
const smallTime = document.createElement('small')
smallTime.textContent = `Last Daily - ${activity.timeframes.daily.previous}hrs`;
divTimer.append(p,imgIcon,h2,smallTime);
article.append(divTimer);
main.append(article);
console.log(activity.timeframes.daily.current);
pDaily.addEventListener('click', e =>{
typeTime(activity.timeframes.daily, "Daily");
changeColor(pDaily,[pWeekly,pMonthly]);
});
pWeekly.addEventListener('click', e =>{
typeTime(activity.timeframes.weekly, "Weekly");
changeColor(pWeekly,[pDaily,pMonthly]);
});
pMonthly.addEventListener('click', e =>{
typeTime(activity.timeframes.monthly, "Monthly");
changeColor(pMonthly,[pDaily,pWeekly])
});
function typeTime(time, name){
h2.textContent = `${time.current}hrs`;
smallTime.textContent = `Last ${name} - ${time.previous}hrs`;
}
});
}
function changeColor(target, options){
target.style.color = "white";
options.forEach(option =>{
option.style.color = "hsl(236, 100%, 87%)";
})
}