-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
80 lines (62 loc) · 2.11 KB
/
scripts.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
const desiredRepo = "MaxRicketts-Uy";
const dateTagClass = ".date";
const headers = ["Week", "Stocks", "Total Invested", "Dividends"];
const generateDivHarvestingTable = () => {
const createElement = (element) => {
return document.createElement(element);
}
const divHarvestingDiv = document.getElementById("dividend-harvesting");
const table = createElement("table");
const headerRow = createElement("tr");
const tBody = createElement("tbody");
if(table !== null && divHarvestingDiv !== null){
headers.forEach((h) => {
let header = createElement("th");
header.innerHTML = h;
headerRow.appendChild(header);
})
table.appendChild(headerRow);
data.forEach((d) => {
const weekRow = createElement("tr");
const weekCell = createElement("td");
const stockCell = createElement("td");
const investedCell = createElement("td");
const divCell = createElement("td");
const weekA = createElement("a");
weekCell.innerHTML = d.week;
stockCell.innerHTML = d.stocks;
investedCell.innerHTML = "$" + d.week * 100;
divCell.innerHTML = "";
weekRow.appendChild(weekCell);
weekRow.appendChild(stockCell);
weekRow.appendChild(investedCell);
weekRow.appendChild(divCell);
tBody.appendChild(weekRow);
})
table.appendChild(tBody);
divHarvestingDiv.appendChild(table);
}
}
window.addEventListener('load', function () {
generateDivHarvestingTable();
})
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function()
{
if (this.readyState == 4 && this.status == 200)
{
let repos = JSON.parse(this.responseText);
repos.forEach((repo)=>{
if (repo.name == desiredRepo)
{
var lastUpdated = new Date(repo.updated_at);
var day = lastUpdated.getUTCDate() - 1;
var month = lastUpdated.getUTCMonth() + 1;
var year = lastUpdated.getUTCFullYear();
document.querySelector(dateTagClass).innerText = `Last updated: ${month}/${day}/${year}`;
}
});
}
};
xhttp.open("GET", "https://api.github.com/users/MaxRickettsUy/repos", true);
xhttp.send();