document.addEventListener('DOMContentLoaded', () => {
getRequest(
'',
drawOutput
);
function drawOutput(responseText) {
let resp = JSON.parse(responseText).financials;
let financials = resp;
let $table = document.createElement("table");
$table.className += " table";
var elements = document.querySelectorAll('.stock-name')[0];
let $head = document.createElement("thead");
let $body = document.createElement("tbody");
let $lineHader = document.createElement("tr");
/* let $elefirst = document.createElement("th");
$elefirst.textContent = 'Fiscal';
$lineHader.appendChild($elefirst); */
for (let i = 0; i < financials.length; i++) {
let financial = financials[i];
let $line = document.createElement("tr");
for (var key in financial) {
if (i === 0 && financial.hasOwnProperty(key)) {
let $ele = document.createElement("th");
$ele.textContent = key;
$lineHader.appendChild($ele);
}
}
$head.appendChild($lineHader);
$table.appendChild($head);
var z = 0;
for (var key2 in financial) {
if (financial.hasOwnProperty(key2)) {
/* if (z === 0) {
let title = Object.keys(resp)[i];
let $eleTile = document.createElement("td");
$eleTile.textContent = title;
$line.appendChild($eleTile);
} */
let $eletd = document.createElement("td");
if (z === 0) {
$eletd.textContent = financial[key2];
} else {
$eletd.textContent = financial[key2];
}
$line.appendChild($eletd);
}
z++;
}
$body.appendChild($line)
$table.appendChild($body);
}
document.body.appendChild($table);
}
function getRequest(url, success) {
var req = false;
try {
req = new XMLHttpRequest();
} catch (e) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
return false;
}
}
}
if (!req) return false;
if (typeof success != 'function') success = function() {};
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status === 200) {
success(req.responseText)
}
}
}
req.open("GET", url, true);
req.send(null);
return req;
}
})