-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
109 lines (96 loc) · 2.58 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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
box-sizing: border-box;
}
#myInput {
background-image: url('/css/searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
width: 100%;
font-size: 16px;
padding: 12px 20px 12px 40px;
border: 1px solid #ddd;
margin-bottom: 12px;
}
#myTable {
border-collapse: collapse;
width: 100%;
border: 1px solid #ddd;
font-size: 18px;
}
#myTable th, #myTable td {
text-align: left;
padding: 12px;
}
#myTable tr {
border-bottom: 1px solid #ddd;
}
#myTable tr.header, #myTable tr:hover {
background-color: #f1f1f1;
}
</style>
</head>
<body>
<h2>Search Kaggle Jobs</h2>
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for Job.." title="Type in ...">
<table id="myTable">
<tr class="header">
<th style="width:40%;">Company Name</th>
<th style="width:60%;">Job Title</th>
</tr>
</table>
<script>
function myFunction() {
var input = document.getElementById("myInput").value;
load(input)
}
</script>
<script>
var init=0;
const load = (input) => {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
if (init!=0){
const removeElements = (elms) => elms.forEach(el => el.remove());
removeElements( document.querySelectorAll(".row") );
}else {
init = 1
}
// Typical action to be performed when the document is ready:
data = JSON.parse(xhttp.responseText);
addRow('myTable', data['resp']);
}
};
xhttp.open("GET", 'https://kaggle-search-engine-demo.herokuapp.com/search?query='+input);
xhttp.send();
}
window.onload = load('');
function addRow(tableID, data) {
// Get a reference to the table
let tableRef = document.getElementById(tableID);
data.map(i => {
// Insert a row at the end of the table
let newRow = tableRef.insertRow(-1);
newRow.className = 'row';
// Insert a cell in the row at index 0
let newCell0 = newRow.insertCell(0);
// Append a text node to the cell
let newText0 = document.createTextNode(i[0]);
newCell0.appendChild(newText0);
let newCell1 = newRow.insertCell(1);
var elLink = document.createElement('a');
var href='https://www.kaggle.com'+i[2].replace("$", "");
elLink.href = href;
elLink.innerHTML = i[1];
elLink.target = "_blank";
newCell1.appendChild(elLink);
})
}
</script>
</body>
</html>