-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
93 lines (85 loc) · 3.24 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
document.getElementById('checkMyUserAgent').addEventListener('click', function() {
fadeOutMain();
setTimeout(() => {
fetchUserAgent(navigator.userAgent);
}, 600);
});
document.getElementById('checkAnotherUserAgent').addEventListener('click', function() {
fadeOutMain();
setTimeout(() => {
document.getElementById('inputSection').style.display = 'block';
fadeIn(document.getElementById('inputSection'));
document.getElementById('goBack').style.display = 'block';
fadeIn(document.getElementById('goBack'));
}, 600);
});
document.getElementById('lookupButton').addEventListener('click', function() {
const userAgent = document.getElementById('userAgentInput').value;
fetchUserAgent(userAgent);
});
document.getElementById('goBack').addEventListener('click', function() {
fadeOut(document.getElementById('resultSection'));
fadeOut(document.getElementById('inputSection'));
fadeOut(document.getElementById('goBack'));
setTimeout(() => {
document.getElementById('description').style.display = 'block';
document.getElementById('checkMyUserAgent').style.display = 'block';
document.getElementById('checkAnotherUserAgent').style.display = 'block';
fadeIn(document.getElementById('description'));
fadeIn(document.getElementById('checkMyUserAgent'));
fadeIn(document.getElementById('checkAnotherUserAgent'));
}, 600);
});
function fetchUserAgent(userAgent) {
const apiUrl = `https://api.apicagent.com/?ua=${encodeURIComponent(userAgent)}`;
fetch(apiUrl)
.then(response => response.json())
.then(data => {
displayResult(data);
});
}
function displayResult(data) {
const resultSection = document.getElementById('resultSection');
resultSection.innerHTML = `
<p><strong>Browser Family:</strong> ${data.browser_family}</p>
<p><strong>Client Name:</strong> ${data.client.name}</p>
<p><strong>Client Version:</strong> ${data.client.version}</p>
<p><strong>Device Brand:</strong> ${data.device.brand}</p>
<p><strong>Device Type:</strong> ${data.device.type}</p>
<p><strong>OS Name:</strong> ${data.os.name}</p>
<p><strong>OS Version:</strong> ${data.os.version}</p>
<p><strong>User Agent:</strong> ${data.user_agent}</p>
`;
fadeOut(document.getElementById('inputSection'));
fadeIn(resultSection);
document.getElementById('goBack').style.display = 'block';
fadeIn(document.getElementById('goBack'));
}
function fadeOutMain() {
fadeOut(document.getElementById('description'));
fadeOut(document.getElementById('checkMyUserAgent'));
fadeOut(document.getElementById('checkAnotherUserAgent'));
}
function fadeIn(element) {
element.style.display = 'block';
element.style.opacity = 0;
let op = 0;
let timer = setInterval(function() {
if (op >= 1) {
clearInterval(timer);
}
element.style.opacity = op;
op += 0.1;
}, 50);
}
function fadeOut(element) {
let op = 1;
let timer = setInterval(function() {
if (op <= 0) {
clearInterval(timer);
element.style.display = 'none';
}
element.style.opacity = op;
op -= 0.1;
}, 50);
}