git ssb

0+

Rômulo Alves / dat-letnice



Tree: c4b5e446a3e34b38835e005437c1091c5d5e3cc0

Files: c4b5e446a3e34b38835e005437c1091c5d5e3cc0 / js / letnice.js

2101 bytesRaw
1function Year()
2{
3 let base = document.getElementById("center");
4
5 const monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
6 const dayNames = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ]
7
8 let year = new Date().getFullYear();
9 let month = 0;
10 let style = "day";
11
12 base.innerHTML += `<div class="header"><p class="y">${year}</p><p class="p">${yearProgress(2018) + "%"}</p></div>`
13
14 while(month < 12)
15 {
16 base.innerHTML += `<div class="month">
17 <p class="m">${monthNames[new Date(year, month).getMonth()].substr(0,2)}</p>
18 <svg class="graph" id="${monthNames[month]}">
19 ${doLabels()}
20 ${doMonth(month)}
21 </svg></div>`
22 month++
23 }
24
25 function doLabels()
26 {
27 let html = "";
28 let y = 0;
29
30 for(i = 0; i < 7; i++)
31 {
32 y = (i * 14)+1;
33 html += `<text class="dayLabel" x="5" y='${y}' dy="10">${dayNames[i].substr(0,1)}</text>`
34 }
35 return html;
36 }
37
38 function doMonth(month)
39 {
40 html = "";
41 monthLength = new Date(year, month+1, 0).getDate();
42 let date = 0;
43 let x = 0;
44 let y = 0;
45
46 while(date < monthLength)
47 {
48 x += 14;
49 let week = 0
50
51 while(week < 7 && date != monthLength)
52 {
53 y = week * 14 + 2;
54 let day = new Date(year, month, date);
55
56 if(day.getDay() != week)
57 {
58 style = "null";
59 date--
60 }
61 else if(day < new Date())
62 {
63 style = "gone";
64 }
65 else if(day.getDay() == 5 || day.getDay() == 6)
66 {
67 style = "weekend";
68 }
69 else
70 {
71 style = "day";
72 }
73
74 html += `<rect class='${style}' x='${x}' y='${y}' title='${dayNames[week] + "_" + (date+1)}' width="12px" height="12px" rx="2" ry="2" onclick=""></rect>`
75 week++
76 date++
77 }
78 }
79 return html;
80 }
81
82 function yearProgress(year)
83 {
84 progress = new Date() - new Date(year, 0, 1, 0);
85 return (progress/31536000000).toFixed(2);
86 }
87}

Built with git-ssb-web