Skip to content
This repository was archived by the owner on Jul 21, 2025. It is now read-only.

Commit 585e425

Browse files
committed
Show the OS on the front page (if we can get it from the user agent).
1 parent 2bed204 commit 585e425

File tree

1 file changed

+56
-16
lines changed

1 file changed

+56
-16
lines changed

domains/misc/badssl.com/index.html

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
margin: 5vh auto;
2121
padding: 0 3vw 0 3vw;
2222
}
23-
#links a, #links #ua {
23+
#links a, #links .browser-info {
2424
font-family: "Source Code Pro", Monaco, Consolas, "Courier New", monospace, Impact;
2525
font-size: 3.5vh;
2626
padding: 0.75vh 10vw 0.75vh 10vw;
@@ -37,17 +37,18 @@
3737
transition: all 150ms;
3838
font-weight: bold;
3939
}
40-
#links #ua {
40+
#links .browser-info {
4141
margin-top: 3vh;
4242
padding: 0.75vh 0vh;
43+
line-height: 1.5em;
4344
}
4445
@media (min-height: 1000px) {
45-
#links a, #links #ua {
46+
#links a, #links .browser-info {
4647
font-size: 2.5vh;
4748
}
4849
}
4950
@media (max-width: 600px) and (min-height: 600px) {
50-
#links a, #links #ua {
51+
#links a, #links .browser-info {
5152
font-size: 5vw;
5253
}
5354
}
@@ -119,28 +120,63 @@
119120
</style>
120121
<script>
121122

122-
function simplifyUserAgent(ua) {
123+
function getBrowserVersion(ua) {
124+
var ua = navigator.userAgent;
125+
123126
var regexes = [
124-
/Chrome\/[\d\.]*\b/,
125-
/CriOS\/[\d\.]*\b/,
126-
/Firefox\/[\d\.]*\b/,
127-
/OPR\/[\d\.]*\b/,
128-
/OPiOS\/[\d\.]*\b/,
129-
/Version\/[\d\.]*\b/ /* Safari has "Version/8.0.5 Safari/600.5.17", but "Safari/600.5.17" is the WebKit version, which Chrome and Opera also include. */
130-
]
127+
128+
[/^.*Chrome\/([\d\.]*)\b.*$/, "Chrome $1"],
129+
[/^.*CriOS\/([\d\.]*)\b.*$/, "Chrome $1"],
130+
[/^.*Firefox\/([\d\.]*)\b.*$/, "Firefox $1"],
131+
[/^.*OPR\/([\d\.]*)\b.*$/, "Opera $1"],
132+
[/^.*OPiOS\/([\d\.]*)\b.*$/, "Opera Mini $1"],
133+
/* This has to go last: Safari has "Version/8.0.5 Safari/600.5.17", but "Safari/600.5.17" is the WebKit version, which Chrome and Opera also include.*/
134+
[/^.*Version\/([\d\.]*)\b.*$/, "Safari $1"]
135+
];
131136

132137
for (i in regexes) {
133-
var match = regexes[i].exec(ua);
138+
var match = regexes[i][0].exec(ua);
134139
if (match) {
135-
return match[0];
140+
return ua.replace(regexes[i][0], regexes[i][1]);
136141
}
137142
}
138143
return ua;
139144
}
140145

146+
function getOS() {
147+
var ua = navigator.userAgent;
148+
149+
var regexes = [
150+
[/^.*Mac OS X (\d+)_(\d+)_(\d+).*$/g, "OSX $1.$2.$3"], // OSX Chrome, OSX Safari, OSX Opera
151+
[/^.*Mac OS X (\d+)_(\d+).*$/g, "OSX $1.$2"], // Just in case?
152+
[/^.*Mac OS X (\d+)\.(\d+).*$/g, "OSX $1.$2"], // OSX Firefox
153+
[/^.*iPhone OS (\d+)_(\d+).*OPiOS.*$/g, null], // iPhone Opera doesn't seem to pick up the OS dynamically?
154+
[/^.*iPhone OS (\d+)_(\d+).*$/g, "iOS $1.$2 (iPhone)"], // iPhone WebKit
155+
[/^.*iPad.*OS (\d+)_(\d+).*$/g, "iOS $1.$2 (iPad)"], // iPad WebKit
156+
[/^.*Android (\d+(\.\d+)+).*; ([^;]+) Build.*$/g, "Android $1 ($3)"], // Android + device name
157+
[/^.*Android (\d+(\.\d+)+).*$/g, "Android $1"],
158+
[/^.*Linux.*$/g, "Linux"],
159+
[/^.*Windows.*$/g, "Windows"],
160+
];
161+
162+
for (i in regexes) {
163+
var match = regexes[i][0].exec(ua);
164+
if (match) {
165+
if (!regexes[i][1]) {
166+
return null;
167+
}
168+
return ua.replace(regexes[i][0], regexes[i][1]);
169+
}
170+
}
171+
return null;
172+
}
173+
141174
window.addEventListener("load", function() {
142175
document.getElementById("ua").title = navigator.userAgent;
143-
document.getElementById("ua").innerHTML = "UA: " + simplifyUserAgent(navigator.userAgent);
176+
document.getElementById("ua").textContent = getBrowserVersion();
177+
if (getOS()) {
178+
document.getElementById("os").textContent = getOS();
179+
}
144180
console.log(navigator.userAgent);
145181
document.getElementById("reveal-more").addEventListener("click", function(e) {
146182
document.getElementById("links").classList.add("show-more");
@@ -184,7 +220,11 @@
184220
<a href="https://mixed.badssl.com/mixed/font" class="more bad no-interstitial">mixed/font</a>
185221
<a href="https://long-extended-subdomain-name-containing-many-letters-and-dashes.badssl.com/" class="more good">long-extended-subdomain-name-containing-many-letters-and-dashes</a>
186222
<a href="https://longextendedsubdomainnamewithoutdashesinordertotestwordwrapping.badssl.com/" class="more good">longextended<wbr>subdomainname<wbr>withoutdashes<wbr>inordertotest<wbr>wordwrapping</a>
187-
<div id="ua"></div>
223+
<div class="browser-info">
224+
<span id="ua"></span>
225+
<br>
226+
<span id="os"></span>
227+
</div>
188228
</div>
189229

190230
<!-- Start of GitHub ribbon. -->

0 commit comments

Comments
 (0)