forked from jakecreps/poastal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
115 lines (98 loc) · 3.77 KB
/
script.js
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
let newsletterLink = null;
document.getElementById('email').addEventListener('keypress', async function (event) {
if (event.key === 'Enter') {
const email = this.value;
const url = `http://localhost:8080/?email=${encodeURIComponent(email)}`;
// Clear table content
document.getElementById('result').innerHTML = '';
// Show loading element
document.getElementById('loading').classList.remove('hidden');
// Hide table header
document.getElementById('result-table').querySelector('thead').classList.add('hidden');
// Remove newsletter link if it exists
if (newsletterLink) {
newsletterLink.remove();
newsletterLink = null;
}
try {
const response = await fetch(url);
const result = await response.json();
displayResults(result);
} catch (error) {
console.error('Error fetching data:', error);
document.getElementById('result').textContent = 'Error: Unable to fetch data.';
} finally {
// Hide loading element
document.getElementById('loading').classList.add('hidden');
}
}
});
function displayResults(data) {
const resultTable = document.getElementById('result');
resultTable.innerHTML = '';
for (const category in data) {
if (category === 'profiles') {
for (const platform in data[category]) {
const row = document.createElement('tr');
const platformCell = document.createElement('td');
platformCell.textContent = platform;
row.appendChild(platformCell);
const resultCell = document.createElement('td');
const icon = document.createElement('img');
icon.width = 16;
icon.height = 16;
if (data[category][platform] === 'true') {
icon.src = './img/true.png';
} else if (data[category][platform] === 'unknown') {
icon.src = './img/unknown.png';
} else {
icon.src = './img/false.png';
}
resultCell.appendChild(icon);
row.appendChild(resultCell);
resultTable.appendChild(row);
}
} else {
const row = document.createElement('tr');
const platformCell = document.createElement('td');
platformCell.textContent = category;
row.appendChild(platformCell);
const resultCell = document.createElement('td');
if (category === 'Name') {
if (data[category] === 'N/A') {
const icon = document.createElement('img');
icon.width = 16;
icon.height = 16;
icon.src = './img/false.png';
resultCell.appendChild(icon);
} else {
resultCell.textContent = data[category];
}
} else {
const icon = document.createElement('img');
icon.width = 16;
icon.height = 16;
if (data[category] === 'true') {
icon.src = './img/true.png';
} else if (data[category] === 'unknown') {
icon.src = './img/unknown.png';
} else {
icon.src = './img/false.png';
}
resultCell.appendChild(icon);
}
row.appendChild(resultCell);
resultTable.appendChild(row);
}
}
// Show table header
document.getElementById('result-table').querySelector('thead').classList.remove('hidden');
// Append the newsletter link after the table if it doesn't exist
if (!newsletterLink) {
const tableContainer = document.getElementById('result-table');
newsletterLink = document.createElement('p');
newsletterLink.innerHTML = '<a href="https://osintnewsletter.com" target="_blank">Subscribe to The OSINT Newsletter</a>';
newsletterLink.id = 'newsletter-link';
tableContainer.parentNode.insertBefore(newsletterLink, tableContainer.nextSibling);
}
}