mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-09-27 16:08:47 +03:00
266 lines
9.0 KiB
HTML
266 lines
9.0 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<title>UAParser.js - Lightweight JavaScript-based User Agent String Parser</title>
|
|
<meta charset="utf-8">
|
|
<meta name="author" content="Faisalman" />
|
|
<meta name="description" content="UAParser.js Lightweight JavaScript-based User-Agent string parser. Supports browser & node.js environment. Also available as jQuery plugin & AMD module." />
|
|
<meta name="keywords" content="user agent, parser, javascript, detect, details, new, browser, engine, mobile, device, operating system" />
|
|
<style>
|
|
@import url("//fonts.googleapis.com/css?family=Raleway");
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
font-family: Raleway, Helvetica, Ubuntu, Arial, Georgia, sans-serif;
|
|
}
|
|
html, input, select {
|
|
font: 14px/20px Helvetica, Ubuntu, Arial, Georgia, sans-serif;
|
|
color: #333;
|
|
}
|
|
body {
|
|
background: #33A6B2;
|
|
margin: 0 auto;
|
|
width: 960px;
|
|
text-align: center;
|
|
}
|
|
header, section, footer {
|
|
padding: 50px;
|
|
position: relative;
|
|
}
|
|
header {
|
|
padding: 100px 50px 50px;
|
|
background-color: #196674;
|
|
color: #fff;
|
|
}
|
|
section {
|
|
background-color: #F0F0F0;
|
|
}
|
|
section.test {
|
|
background-color: #218777;
|
|
}
|
|
footer {
|
|
background-color: #33332D;
|
|
color: #fff;
|
|
}
|
|
footer a {
|
|
color: #fff;
|
|
}
|
|
h1 a {
|
|
text-decoration: none;
|
|
color: #fff;
|
|
}
|
|
h1 {
|
|
margin-bottom: 30px;
|
|
font-size: 4em;
|
|
}
|
|
h2 {
|
|
font-size: 1.2em;
|
|
}
|
|
.share {
|
|
position: absolute;
|
|
width: 100px;
|
|
height: 20px;
|
|
top: 60px;
|
|
right: 0;
|
|
}
|
|
pre {
|
|
font-size: 1em;
|
|
padding: 10px;
|
|
white-space: pre-wrap;
|
|
overflow: auto;
|
|
line-height: 2em;
|
|
}
|
|
table {
|
|
margin: 50px 0;
|
|
border-spacing: 0;
|
|
width: 100%;
|
|
}
|
|
th {
|
|
font-size: 2em;
|
|
}
|
|
th, td {
|
|
min-width: 100px;
|
|
padding: 20px;
|
|
text-align: center;
|
|
}
|
|
td {
|
|
font-size: 1.2em;
|
|
color: #333;
|
|
}
|
|
select, input, .grey {
|
|
color: #777;
|
|
width: 95%;
|
|
}
|
|
select, input {
|
|
background-color: #fff;
|
|
border: 1px solid #ccc;
|
|
height: 40px;
|
|
padding: 0 10px;
|
|
margin: 10px;
|
|
}
|
|
hr {
|
|
border: 0;
|
|
margin: 20px 0;
|
|
}
|
|
p {
|
|
margin: 10px 0;
|
|
font-size: 1em;
|
|
line-height: 1.5em;
|
|
}
|
|
.ua {
|
|
font-size: 1.5em;
|
|
}
|
|
.uastring {
|
|
background-color: #33332D;
|
|
color: #f0f0f0;
|
|
font-weight: bold;
|
|
padding: 5px 10px;
|
|
}
|
|
</style>
|
|
<script src="src/ua-parser.js"></script>
|
|
<script src="ua-list-example.js"></script>
|
|
</head>
|
|
<body>
|
|
<header>
|
|
<h1><a href="https://faisalman.github.io/ua-parser-js">UAParser.js</a></h1>
|
|
<h2>Lightweight JavaScript-based User-Agent String Parser</h2>
|
|
</header>
|
|
<section class="result">
|
|
<pre>
|
|
</pre>
|
|
<table>
|
|
<tr>
|
|
<th>Browser</th>
|
|
<th>Engine</th>
|
|
<th>OS</th>
|
|
<th>Device</th>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
</tr>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</section>
|
|
<section class="test">
|
|
<p>Pick one user agent to be tested:</p>
|
|
<select>
|
|
<option>Pick one</option>
|
|
</select>
|
|
<p>Or enter any user-agent string you want to test here:</p>
|
|
<input type="text" />
|
|
</section>
|
|
<footer>
|
|
<p>
|
|
<span class="ua">UAParser.js</span> © 2012-2014 Faisal Salman. <br/>
|
|
Dual licensed under GPLv2 & MIT license<br/>
|
|
Source & Docs: <a href="https://github.com/faisalman/ua-parser-js">https://github.com/faisalman/ua-parser-js</a><br/>
|
|
Node.js package: <a href="https://npmjs.org/package/ua-parser-js">https://npmjs.org/package/ua-parser-js</a><br/>
|
|
$.ua: <a href="http://plugins.jquery.com/ua-parser-js/">http://plugins.jquery.com/ua-parser-js/</a>
|
|
</p>
|
|
</footer>
|
|
<script>
|
|
var pre = document.getElementsByTagName('pre')[0];
|
|
var sel = document.getElementsByTagName('select')[0];
|
|
var txt = document.getElementsByTagName('input')[0];
|
|
var parser = new UAParser();
|
|
var fill = function(el, prop){
|
|
if(typeof prop === 'object'){
|
|
el.innerHTML = '';
|
|
el.appendChild(prop);
|
|
} else if(typeof prop === 'string'){
|
|
el.innerHTML = prop;
|
|
} else {
|
|
el.innerHTML = "-";
|
|
}
|
|
};
|
|
var imgMap = function(prop, dir, key, arr){
|
|
var img = document.createElement('img');
|
|
img.src = 'images/undefined.png';
|
|
img.width = 64;
|
|
img.height = 64;
|
|
for(var i in arr){
|
|
if(arr.hasOwnProperty(i)){
|
|
var isobj = typeof arr[i] === 'object';
|
|
var r = isobj ? new RegExp(arr[i][0], 'i') : new RegExp(arr[i], 'i');
|
|
if(r.test(prop[key]) && dir!='engine'){
|
|
img.src = 'images/'+dir+'/'+(isobj?arr[i][1]:arr[i])+'.png';
|
|
return img;
|
|
} else if(prop[key] !== undefined){
|
|
img.src = 'images/check.png';
|
|
}
|
|
}
|
|
}
|
|
img.onerror = function() {
|
|
this.src = 'images/check.png';
|
|
this.onerror = null;
|
|
};
|
|
return img;
|
|
};
|
|
for(var i = 0; i < uaExampleList.length; i++){
|
|
var opt = document.createElement('option');
|
|
opt.innerHTML = uaExampleList[i];
|
|
sel.appendChild(opt);
|
|
}
|
|
var fillTable = function(uastring){
|
|
if(uastring) parser.setUA(uastring);
|
|
var browser = parser.getBrowser();
|
|
var engine = parser.getEngine();
|
|
var os = parser.getOS();
|
|
var device = parser.getDevice();
|
|
var tbl = document.getElementsByTagName('td');
|
|
var prop = [
|
|
imgMap(browser, 'browser', 'name', [['ie', 'internet-explorer-tile'], 'chrome', 'chromium', 'konqueror', 'safari', 'opera', 'firefox', 'fennec', 'mozilla', 'midori', 'arora', 'camino', 'iceweasel', 'flock', 'avant', 'baidu', 'dolphin', 'epiphany', ['icab', 'icab-mobile'], 'iceape', 'icecat', ['lunascape', 'ilunascape-android'], 'maxthon', ['netscape', 'netscape_4-6'], 'netsurf', 'omniweb', ['qqbrowser', 'qq'], 'rockmelt', 'rekonq', 'seamonkey', ['silk', 'silk_1'], ['skyfire', 'skyfire-ios'], ['ucbrowser', 'uc'], ['uc browser', 'uc'], 'yandex']),
|
|
imgMap(engine, 'engine', 'name', [['trident', 'ie'], ['webkit', 'safari'], ['khtml', 'konqueror'], ['presto', 'opera'], ['gecko', 'mozilla']]),
|
|
imgMap(os, 'os', 'name', ['meego', 'symbian', 'android', 'blackberry', 'bada', ['windows phone os', 'winphone'], 'windows', 'chromium', 'mac', 'freebsd', 'bsd', 'kubuntu', 'xubuntu', 'lubuntu', 'ubuntu', 'gentoo', 'fedora', 'mandriva', 'redhat', 'suse', 'debian', 'slackware', 'arch', 'linux', 'solaris', 'webos', 'centos', 'pclinuxos', ['ios', 'mac'], ['rim', 'blackberry'], 'qnx', 'gnu', 'playstation', 'wii', 'xbox', 'unix']),
|
|
imgMap(device, 'device', 'type', [['undefined', 'pc'], 'console', 'tablet', ['mobile', 'phone'], ['smarttv', 'tv']]),
|
|
browser.name, engine.name, os.name, device.vendor,
|
|
browser.version, engine.version, os.version, device.model];
|
|
for(var i = 0; i < prop.length; i++){
|
|
fill(tbl[i], prop[i]);
|
|
}
|
|
pre.innerHTML = 'Result for <span class="uastring">' + (uastring ? uastring.replace(/</g,'<') : navigator.userAgent + '</span><span> (User-Agent string of your browser)') + '</span> :';
|
|
}
|
|
fillTable();
|
|
var select = function(){
|
|
fillTable(sel.children[sel.selectedIndex].value);
|
|
};
|
|
var enter = function(e){
|
|
if(e.keyCode == 13){
|
|
fillTable(this.value);
|
|
return false;
|
|
}
|
|
};
|
|
if (window.addEventListener) {
|
|
sel.addEventListener('change', select);
|
|
txt.addEventListener('keydown', enter);
|
|
} else {
|
|
sel.attachEvent('onchange', select);
|
|
txt.attachEvent('onkeydown', enter);
|
|
}
|
|
</script>
|
|
<script type="text/javascript">
|
|
var _gaq = _gaq || [];
|
|
_gaq.push(['_setAccount', 'UA-3767301-5']);
|
|
_gaq.push(['_trackPageview']);
|
|
(function() {
|
|
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
|
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
|
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|