function parseAgent(agent) {
var browserlist = [
["MSIE 5.0", "IE5"],
["MSIE 6.0", "IE6"],
["MSIE 10.0", "IE10"],
["Trident/7.0; rv:11.0", "IE11"],
["QupZilla", "QupZilla"],
["Iceweasel", "Iceweasel"],
["Firefox", "Mozilla Firefox"],
["Chrome", "Google Chrome"],
["Chromium", "Chromium"],
["Opera", "Opera"],
["OPR", "Opera"],
["UCBrowser", "UCBrowser"],
["Safari", "Apple Safari"],
["Konqueror", "Konqueror"],
["libwww", "Lynx"],
["Links", "Links"],
["w3m", "W3M"],
["Otter", "Otter"],
["Midori", "Midori"],
["Origyn Web Browser", "Origyn Web Browser"],
["OWB", "Origyn Web Browser"],
["IBrowse", "IBrowse"],
["Amiga-AWeb", "Amiga AWeb"]
];
var oslist = [
["Windows 98", "Windows 98"],
["Windows NT 5.1", "Windows XP"],
["Windows NT 6.1", "Windows 7"],
["Windows NT 6.2", "Windows 8"],
["J2ME/MIDP", "Java"],
["Mac OS X", "Mac OS X"],
["AmigaOS 3.1", "AmigaOS 3.1"],
["AmigaOS 4.0", "AmigaOS 4.0"],
["AmigaOS4.0", "AmigaOS 4.0"],
["AROS", "AROS"],
["MorphOS", "MorphOS"],
["iPhone", "Apple iOS"],
["FreeBSD", "FreeBSD"],
["Ubuntu", "Ubuntu"],
["Debian", "Debian"],
["Android", "Android"],
["Linux", "Linux"]
];
var archlist = [
["i386", "x86"],
["i686", "x86"],
["AMD64", "x86_64"],
["WOW64", "x86_64"],
["x86_64", "x86_64"],
["ARM", "ARM"],
["PPC", "PowerPC"],
["PowerPC", "PowerPC"],
["68K", "Motorola 68K"]
];
var exceptlist = [
["Mozilla/5.0 (Linux; U; Android 4.2.2; hu-hu; Galaxy Nexus Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30", ["Android WebKit", "Android", "unknown"]],
["Mozilla/5.0 (Linux; U; Android 2.3.6; hu-hu; GT-S5660 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1", ["Android WebKit", "Android", "unknown"]],
["Mozilla/5.0 (Linux; U; Android 4.2.2; hu-hu; Galaxy Nexus Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30", ["Android WebKit", "Android", "unknown"]],
["Mozilla/5.0 (Linux; U; Android 2.3.6; hu-hu; GT-I9070P Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1", ["Android WebKit", "Android", "unknown"]],
["Mozilla/5.0 (Linux; U; Android 4.1.1; hu-hu; ALCATEL ONE TOUCH 5020X Build/JRO03C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.1 Mobile Safari/534.30", ["Android WebKit", "Android", "unknown"]],
["Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; ARM; Touch; WPDesktop)", ["IE10", "WP8", "ARM"]],
];
for (var i = 0; i < exceptlist.length; i++) {
if (agent == exceptlist[i][0]) {
return exceptlist[i][1];
}
}
var res = ["unknown", "unknown", "unknown"]; // [browser, os, arch]
for (var i = 0; i < browserlist.length; i++) {
if (agent.indexOf(browserlist[i][0]) > -1) {
res[0] = browserlist[i][1];
break;
}
}
for (var i = 0; i < oslist.length; i++) {
if (agent.indexOf(oslist[i][0]) > -1) {
res[1] = oslist[i][1];
break;
}
}
for (var i = 0; i < archlist.length; i++) {
if (agent.indexOf(archlist[i][0]) > -1) {
res[2] = archlist[i][1];
break;
}
}
return res;
}
Ennyi. Oké, négy listát kell karbantartani (az androidos gyári böngészőt pl. alapból Safarinak detektálja, ezért a kivételeket is kezelni kell), de csak akkor kell hozzányúlni, ha valaki valami nagyon extrém böngészővel jön fel (vagy androidos gyári böngészővel, vagy winfosfónnal, :P de abból kevés van). A listák első elemét keresi az agentben, a másodikba akár meg lehet adni az ikonokra mutató URL-eket. |