forked from MediaBrowser/emby-webcomponents
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowser.js
112 lines (86 loc) · 3.24 KB
/
browser.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
define(['isMobile'], function (isMobile) {
function isTv() {
// This is going to be really difficult to get right
var userAgent = navigator.userAgent.toLowerCase();
if (userAgent.indexOf('tv') != -1) {
return true;
}
if (userAgent.indexOf('samsungbrowser') != -1) {
return true;
}
if (userAgent.indexOf('nintendo') != -1) {
return true;
}
if (userAgent.indexOf('viera') != -1) {
return true;
}
if (userAgent.indexOf('webos') != -1) {
return true;
}
return false;
}
var uaMatch = function (ua) {
ua = ua.toLowerCase();
var match = /(edge)[ \/]([\w.]+)/.exec(ua) ||
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||
/(opr)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||
/(chrome)[ \/]([\w.]+)/.exec(ua) ||
/(safari)[ \/]([\w.]+)/.exec(ua) ||
/(firefox)[ \/]([\w.]+)/.exec(ua) ||
/(msie) ([\w.]+)/.exec(ua) ||
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) ||
[];
var platform_match = /(ipad)/.exec(ua) ||
/(iphone)/.exec(ua) ||
/(android)/.exec(ua) ||
[];
var browser = match[1] || "";
if (browser == "edge") {
platform_match = [""];
} else {
if (ua.indexOf("windows phone") != -1 || ua.indexOf("iemobile") != -1) {
// http://www.neowin.net/news/ie11-fakes-user-agent-to-fool-gmail-in-windows-phone-81-gdr1-update
browser = "msie";
}
else if (ua.indexOf("like gecko") != -1 && ua.indexOf('webkit') == -1 && ua.indexOf('opera') == -1 && ua.indexOf('chrome') == -1 && ua.indexOf('safari') == -1) {
browser = "msie";
}
}
if (browser == 'opr') {
browser = 'opera';
}
return {
browser: browser,
version: match[2] || "0",
platform: platform_match[0] || ""
};
};
var userAgent = window.navigator.userAgent;
var matched = uaMatch(userAgent);
var browser = {};
if (matched.browser) {
browser[matched.browser] = true;
browser.version = matched.version;
}
if (matched.platform) {
browser[matched.platform] = true;
}
if (!browser.chrome && !browser.msie && !browser.edge && !browser.opera && userAgent.toLowerCase().indexOf("webkit") != -1) {
browser.safari = true;
}
if (userAgent.toLowerCase().indexOf("playstation 4") != -1) {
browser.ps4 = true;
browser.tv = true;
}
if (isMobile.any) {
browser.mobile = true;
}
browser.xboxOne = userAgent.toLowerCase().indexOf('xbox') != -1;
browser.animate = document.documentElement.animate != null;
browser.tizen = userAgent.toLowerCase().indexOf('tizen') != -1;
browser.web0s = userAgent.toLowerCase().indexOf('Web0S'.toLowerCase()) != -1;
browser.tv = isTv();
browser.operaTv = browser.tv && userAgent.toLowerCase().indexOf('opr/') != -1;
browser.noFlex = (browser.tv && !browser.chrome && !browser.operaTv) || browser.ps4;
return browser;
});