-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistings.html
More file actions
86 lines (73 loc) · 2.64 KB
/
listings.html
File metadata and controls
86 lines (73 loc) · 2.64 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Listings</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="card">
<h2>Listings</h2>
<ul id="results"></ul>
<button id="logout">Log out</button>
</div>
<script>
const REFRESH_MS = 60000;
document.addEventListener('DOMContentLoaded', () => {
if (localStorage.getItem('loggedIn') !== 'true') {
window.location.href = 'login.html';
return;
}
document.getElementById('logout').addEventListener('click', function () {
localStorage.removeItem('loggedIn');
window.location.href = 'login.html';
});
const resultsList = document.getElementById('results');
async function loadResults() {
try {
const response = await fetch('search_results.json?_=' + Date.now());
const data = await response.json();
resultsList.innerHTML = '';
data.forEach(item => {
const li = document.createElement('li');
li.className = 'result-item';
const img = document.createElement('img');
const url = new URL(item.href);
img.src = 'https://www.google.com/s2/favicons?domain=' + url.hostname;
img.alt = (item.company || url.hostname) + ' logo';
const info = document.createElement('div');
info.className = 'result-info';
const link = document.createElement('a');
link.href = item.href;
link.textContent = item.title;
link.target = '_blank';
link.className = 'result-title';
const company = document.createElement('div');
company.className = 'result-company';
if (item.company) {
company.textContent = item.company;
} else {
const hostParts = url.hostname.replace('www.', '').split('.');
company.textContent = hostParts[hostParts.length - 2] || url.hostname;
}
const desc = document.createElement('div');
desc.className = 'result-description';
desc.textContent = item.body || '';
info.appendChild(link);
info.appendChild(company);
info.appendChild(desc);
li.appendChild(img);
li.appendChild(info);
resultsList.appendChild(li);
});
} catch (e) {
console.error('Failed to load results', e);
}
}
loadResults();
setInterval(loadResults, REFRESH_MS);
});
</script>
</body>
</html>