forked from digitalocean/sample-html
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
127 lines (114 loc) · 3.46 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
<html>
<head>
<meta charset="UTF-8" />
<title>WebSocket Example</title>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th,
td {
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<form>
<label for="keyword">Filter by keyword:</label>
<input type="text" id="keyword" name="keyword" />
<button type="button" onclick="filterTable()">Filter</button>
</form>
<br />
<table id="domainTable">
<thead>
<tr>
<th>Domain</th>
</tr>
</thead>
<tbody id="domainTableBody"></tbody>
</table>
<script>
const tableBody = document.querySelector("table tbody");
const keywordInput = document.getElementById("keyword");
const tableData = [];
function createTableRows(allDomains) {
tableBody.innerHTML = "";
allDomains.forEach((domains) => {
domains.forEach((domain) => {
const row = document.createElement("tr");
const domainCell = document.createElement("td");
domainCell.textContent = domain;
row.appendChild(domainCell);
tableBody.appendChild(row);
});
});
}
function filterTable() {
const keyword = keywordInput.value.trim().toLowerCase();
const rows = tableBody.querySelectorAll("tr");
rows.forEach((row) => {
const domain = row.querySelector("td").textContent.trim().toLowerCase();
const shouldHide = !domain.includes(keyword);
row.style.display = shouldHide ? "none" : "";
});
}
const ws = new WebSocket("wss://lobster-app-d249x.ondigitalocean.app/");
ws.onopen = () => {
console.log("WebSocket is open now.");
ws.send("Hello Server!");
};
// listen for messages from the websocket
ws.onmessage = function (event) {
var message = JSON.parse(event.data);
if (message.message_type === "certificate_update") {
// get the domains from the websocket message
var domains = message.data.leaf_cert.all_domains;
// add the domains to the table data
for (var i = 0; i < domains.length; i++) {
var domain = domains[i];
if (tableData.indexOf(domain) === -1) {
tableData.push(domain);
}
}
// clear the table and repopulate with the updated data
var tableBody = document.getElementById("domainTableBody");
tableBody.innerHTML = "";
for (var i = 0; i < tableData.length; i++) {
var row = tableBody.insertRow();
var cell = row.insertCell();
cell.innerHTML = tableData[i];
}
// Add the search filter to the HTML table
var input = document.getElementById("searchInput");
input.addEventListener("keyup", function () {
var filter = input.value.toUpperCase();
var table = document.getElementById("domainTable");
var tr = table.getElementsByTagName("tr");
for (var i = 0; i < tr.length; i++) {
var td = tr[i].getElementsByTagName("td")[0];
if (td) {
var txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
});
}
};
ws.onerror = (error) => {
console.error("WebSocket Error:", error);
};
ws.onclose = () => {
console.log("WebSocket is closed now.");
};
</script>
</body>
</html>