Commit cfbdf5e7 authored by Sanjit Singh Chouhan's avatar Sanjit Singh Chouhan

Schedule Page from csv without jquery

parent 15e82055
This diff is collapsed.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Summer of Data</title>
<script src="jquery-3.3.1.min.js"></script>
</head>
<body>
<h1 align="center">Summer of Data</h1>
<h2 align="center">Schedule for <span id="date_placeholder"></span></h2>
<table border="1" align="center">
<thead>
<tr>
<th width="10%">S.No</th>
<th width="50%">Name</th>
<th width="30%">Timing</th>
</tr>
</thead>
<tbody id="schedule_table_body">
</tbody>
</table>
<script src="schedule.js"></script>
</body>
</html>
\ No newline at end of file
var today = new Date();
const monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
var date_text = today.getDate() + ' ' + monthNames[today.getMonth()] + ' ' + today.getFullYear();
document.getElementById("date_placeholder").appendChild(document.createTextNode(date_text));
$(document).ready(function() {
$.ajax({
type: "GET",
url: "data.csv",
dataType: "text",
success: function(data) {processData(data);}
});
});
var table = document.getElementById('schedule_table_body');
function processData(allText) {
var allTextLines = allText.split(/\r\n|\n/);
var headers = allTextLines[0].split(',');
var s_no = 1;
for (var i=1; i<allTextLines.length; i++) {
var data = allTextLines[i].split(',');
if (data.length == headers.length) {
var tarr = {};
for (var j=0; j<headers.length; j++) {
tarr[headers[j]]=data[j];
}
var record_date = new Date(tarr.date.replace( /(\d)\/(\d)\/(\d)/, "$2/$1/$3"));
console.log(record_date);
console.log(today);
if (record_date.getDate() == today.getDate() && record_date.getMonth() == today.getMonth() && record_date.getFullYear() == today.getFullYear()) {
var row = document.createElement("tr");
var sno = document.createElement("td");
sno.appendChild(document.createTextNode(s_no));
row.appendChild(sno);
var name = document.createElement("td");
name.appendChild(document.createTextNode(tarr.name));
row.appendChild(name);
var timing = document.createElement("td");
timing.appendChild(document.createTextNode(tarr.start + ' - ' + tarr.end));
row.appendChild(timing);
table.appendChild(row);
s_no++;
}
}
}
}
\ No newline at end of file
......@@ -25,7 +25,6 @@ var schedule = document.createElement("div");
schedule.className = 'summer-of-data';
schedule.style.display = 'none';
var url = browser.extension.getURL('schedule.html');
console.log(url);
document.body.insertBefore(schedule, document.body.firstChild);
......@@ -40,30 +39,27 @@ schedule_btn.addEventListener("click", evt => {
document.getElementsByClassName('summer-of-data').item(0).style.display = 'block';
document.getElementsByClassName('summer-of-data').item(1).style.display = 'block';
schedule.innerHTML = '\
\
<!DOCTYPE html>\n' +
'<html lang="en">\n' +
' <script src="jquery-3.3.1.min.js"></script>\n' +
'<body>\n' +
'<h1 align="center">Summer of Data</h1>\n' +
'<h2 align="center">Schedule for <span id="date_placeholder"></span></h2>\n' +
'\n' +
'<table border="1" align="center">\n' +
' <thead>\n' +
' <tr>\n' +
' <th width="10%">S.No</th>\n' +
' <th width="50%">Name</th>\n' +
' <th width="30%">Timing</th>\n' +
' </tr>\n' +
' </thead>\n' +
' <tbody id="schedule_table_body">\n' +
' </tbody>\n' +
'</table>\n' +
'\n' +
'<script src="schedule.js"></script>\n' +
'</body>\n' +
'</html>';
schedule.style.width = '100%';
schedule.style.height = '100%';
schedule.style.backgroundColor = 'white';
schedule.style.color = 'black !important';
schedule.innerHTML = `
<h1 style="color: #000;" align="center">Summer of Data</h1>
<h2 style="color: #000;" align="center">Schedule for <span id="date_placeholder"></span></h2>
<table border="1" align="center" width="80%">
<thead>
<tr>
<th width="10%">S.No</th>
<th width="50%">Name</th>
<th width="30%">Timing</th>
</tr>
</thead>
<tbody id="schedule_table_body">
</tbody>
</table>
`;
var today = new Date();
const monthNames = ["January", "February", "March", "April", "May", "June",
......@@ -72,15 +68,19 @@ schedule_btn.addEventListener("click", evt => {
var date_text = today.getDate() + ' ' + monthNames[today.getMonth()] + ' ' + today.getFullYear();
document.getElementById("date_placeholder").appendChild(document.createTextNode(date_text));
var url = browser.extension.getURL('data.csv');
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
//... The content has been read in xhr.responseText
processData(xhr.responseText);
}
};
xhr.send();
$(document).ready(function() {
$.ajax({
type: "GET",
url: "data.csv",
dataType: "text",
success: function(data) {processData(data);}
});
});
var table = document.getElementById('schedule_table_body');
......@@ -89,16 +89,16 @@ schedule_btn.addEventListener("click", evt => {
var headers = allTextLines[0].split(',');
var s_no = 1;
for (var i=1; i<allTextLines.length; i++) {
for (var i = 1; i < allTextLines.length; i++) {
var data = allTextLines[i].split(',');
if (data.length == headers.length) {
var tarr = {};
for (var j=0; j<headers.length; j++) {
tarr[headers[j]]=data[j];
for (var j = 0; j < headers.length; j++) {
tarr[headers[j]] = data[j];
}
var record_date = new Date(tarr.date.replace( /(\d)\/(\d)\/(\d)/, "$2/$1/$3"));
var record_date = new Date(tarr.date.replace(/(\d)\/(\d)\/(\d)/, "$2/$1/$3"));
console.log(record_date);
console.log(today);
if (record_date.getDate() == today.getDate() && record_date.getMonth() == today.getMonth() && record_date.getFullYear() == today.getFullYear()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment