-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
142 lines (140 loc) · 7.86 KB
/
index.html
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>CrocPapers - Pandhi.Org</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous">
<link href="site.css" rel="stylesheet" />
</head>
<body style="padding: 2% 10%;">
<div class="container">
<h1>CrocPapers</h1>
<br />
<table id="myTable" class="table table-striped table-borderless table-hover table-responsive"></table>
<br />
<hr />
<br />
<a href="https://github.com/PandhiOrg/CrocPapers/blob/main/LICENSE">Licensed under the very permissive UNLICENSE</a>
<br />
<small><a href="https://pandhi.org">Academic resource collated by pandhi.Org</a></small> | All information presented is from the public domain or under the fair-use doctrine.
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe" crossorigin="anonymous"></script>
<link href="https://cdn.datatables.net/v/dt/jq-3.6.0/jszip-2.5.0/dt-1.13.4/b-2.3.6/b-colvis-2.3.6/b-html5-2.3.6/b-print-2.3.6/cr-1.6.2/date-1.4.0/datatables.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/v/dt/jq-3.6.0/jszip-2.5.0/dt-1.13.4/b-2.3.6/b-colvis-2.3.6/b-html5-2.3.6/b-print-2.3.6/cr-1.6.2/date-1.4.0/datatables.min.js"></script>
<script>
const files = ['cp.json', 'gg.json'];
// Create a function to load a single file and append its data to the table
function loadFileAndAppendTable(fileName, callback) {
// Load JSON file
fetch(fileName)
.then(response => response.json())
.then(data => {
const species = fileName === "cpOut.json" ? "C palustris" : "G gangeticus";
// Append table header
const table = document.querySelector('#myTable');
if (table.tHead === null) {
const thead = table.createTHead();
const row = thead.insertRow();
const th1 = document.createElement('th'); // add a new header cell for Species column
th1.textContent = 'Species';
row.appendChild(th1);
for (let key in data[0]) {
if (key !== 'Link' && key !== 'FileType' && key !== 'CiteCount' && key !== 'CiteLink') { // exclude Link, FileType, CiteCount and CiteLink properties
const th = document.createElement('th');
const text = document.createTextNode(key);
th.appendChild(text);
row.appendChild(th);
}
}
const th = document.createElement('th'); // create a new header cell for the link
const text = document.createTextNode('Link');
th.appendChild(text);
row.appendChild(th);
}
// Append table body
const tbody = table.tBodies[0] || table.createTBody();
data.forEach(obj => {
const row = tbody.insertRow();
const cell1 = row.insertCell(); // add a new cell for the Species column
const text1 = document.createTextNode(species);
cell1.appendChild(text1);
for (let key in obj) {
if (key !== 'Link' && key !== 'FileType' && key !== 'CiteCount' && key !== 'CiteLink') { // exclude Link, FileType, CiteCount and CiteLink properties
const cell = row.insertCell();
const text = document.createTextNode(obj[key]);
cell.appendChild(text);
}
}
const cell = row.insertCell(); // create a new cell for the link
if (obj.Link !== null) {
const a = document.createElement('a');
a.href = obj.Link;
a.textContent = obj.FileType;
cell.appendChild(a);
}
});
// Call the callback function after all data has been added to the table
if (callback) {
callback();
}
});
}
// Load and append data from all files, and execute the callback function when done
let loadedCount = 0;
const totalFiles = files.length;
files.forEach(fileName => {
loadFileAndAppendTable(fileName, () => {
loadedCount++;
if (loadedCount === totalFiles) {
$('#myTable thead th').each(function () {
var title = $(this).text();
$(this).html('<input type="text" placeholder="Search ' + title + '" />');
});
let i = false;
$('#myTable').DataTable({
dom: 'Bifr<t><p><"len"l>',
buttons: ['copy', 'csv', 'excel', 'pdf', 'print'],
colReorder: true,
searchBuilder: {},
initComplete: function () {
// Apply the search
this.api()
.columns()
.every(function () {
if (i === false) {
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo($(column.header()).empty())
.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex($(this).val());
column.search(val ? '^' + val + '$' : '', true, false).draw();
});
column
.data()
.unique()
.sort()
.each(function (d, j) {
select.append('<option value="' + d + '">' + d + '</option>');
});
i = true;
}
else {
var that = this;
$('input', this.header()).on('keyup change clear', function () {
if (that.search() !== this.value) {
that.search(this.value).draw();
}
});
}
});
},
});
}
});
});
</script>
</body>
</html>