-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
154 lines (130 loc) · 5.23 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
function parseUserAgent() {
const userAgent = navigator.userAgent;
const browser = detectBrowser(userAgent);
const browserVersion = detectBrowserVersion(userAgent);
const ipAddressElement = document.getElementById('ipAddress'); // Get the element for IP address
const webGLSupport = detectWebGLSupport();
const canvasSupport = detectCanvasSupport();
const timeZone = getTimeZone();
const languages = getLanguages();
// Use a service like ipify.org to fetch the user's IP address
fetch('https://api.ipify.org?format=json')
.then(response => response.json())
.then(data => {
const ipAddress = data.ip || "Not Available";
ipAddressElement.textContent = ipAddress;
})
.catch(error => {
console.error('Error fetching IP address:', error);
ipAddressElement.textContent = "Not Available";
});
document.getElementById('userAgent').textContent = userAgent;
document.getElementById('browser').textContent = browser;
document.getElementById('browserVersion').textContent = browserVersion;
document.getElementById('webGLSupport').textContent = webGLSupport;
document.getElementById('canvasSupport').textContent = canvasSupport;
document.getElementById('timeZone').textContent = timeZone;
document.getElementById('languages').textContent = languages;
}
function detectBrowser(userAgent) {
if (userAgent.includes("Chrome")) {
return "Chrome";
} else if (userAgent.includes("Firefox")) {
return "Firefox";
} else if (userAgent.includes("Safari")) {
return "Safari";
} else if (userAgent.includes("Edge")) {
return "Edge";
} else if (userAgent.includes("Opera")) {
return "Opera";
} else {
return "Unknown";
}
}
function detectBrowserVersion(userAgent) {
// Extract and return the browser version from the user agent string
// Example: "Chrome/94.0.4606.71"
const match = userAgent.match(/(Chrome|Firefox|Safari|Edge|Opera)\/([\d.]+)/);
return match ? match[2] : "Unknown";
}
function detectWebGLSupport() {
// Check if WebGL is supported in the user's browser
const canvas = document.createElement('canvas');
const gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
return gl ? "Supported" : "Not Supported";
}
function detectCanvasSupport() {
// Check if Canvas is supported in the user's browser
const canvas = document.createElement('canvas');
return canvas.getContext ? "Supported" : "Not Supported";
}
function getTimeZone() {
// Get and return the user's time zone
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
return timeZone || "Unknown";
}
function getLanguages() {
// Get and return the user's preferred languages
const languages = navigator.languages || [navigator.language || navigator.userLanguage];
return languages.join(", ") || "Unknown";
}
function detectOS() {
const userAgent = navigator.userAgent;
let os = "Unknown";
if (userAgent.includes("Windows")) {
os = "Windows";
} else if (userAgent.includes("Mac OS")) {
os = "Mac OS";
} else if (userAgent.includes("Linux")) {
os = "Linux";
} else if (userAgent.includes("Android")) {
os = "Android";
} else if (userAgent.includes("iOS")) {
os = "iOS";
}
return os;
}
// Usage example:
const os = detectOS();
document.getElementById('os').textContent = os;
function detectDevice(userAgent) {
const userAgentLC = userAgent.toLowerCase();
if (userAgentLC.includes("iphone")) {
return "iPhone";
} else if (userAgentLC.includes("ipad")) {
return "iPad";
} else if (userAgentLC.includes("android")) {
return "Android Device";
} else if (userAgentLC.includes("macintosh")) {
return "Macintosh";
} else if (userAgentLC.includes("windows")) {
return "Windows PC";
} else if (userAgentLC.includes("linux")) {
return "Linux PC";
} else {
return "Unknown";
}
}
// Usage example:
const userAgent = navigator.userAgent;
const device = detectDevice(userAgent);
document.getElementById('device').textContent = device;
// Trigger the user agent parsing when the page loads
window.onload = parseUserAgent;
// Function to copy the User-Agent string to the clipboard and play a sound
function copyUserAgent() {
const userAgentText = document.getElementById('userAgent');
const userAgent = userAgentText.textContent;
const textArea = document.createElement('textarea');
textArea.value = userAgent;
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
// Change the button text to indicate successful copying
const copyButton = document.querySelector('.copy-button');
copyButton.textContent = 'Copied!';
// Play a sound when copying is done
const audio = new Audio('copy-sound.mp3'); // Replace 'copy-sound.mp3' with your sound file
audio.play();
}