forked from wwmin/JavaScript30
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.js
More file actions
195 lines (181 loc) · 5.46 KB
/
shell.js
File metadata and controls
195 lines (181 loc) · 5.46 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/**
* 浏览器内核判断
*/
function getUserAgentInfoFoo() {
var ua = {};
var win = window;
var nav = win.navigator;
var doc = win.document;
var ieAX = win.ActiveXObject;
var ieMode = doc.documentMode;
var REG_APPLE = /^Apple/;
var ieVer = _getIeVersion() || ieMode || 0;
var isIe = ieAX || ieMode;
var regEdge = /Edge/i;
var regChromeVersion = /(?:Chrome\/)(\d+)(?:\.)/i;
var chromiumType = _getChromiumType();
/**
* 检测 external 是否包含该字段
* @param reg 正则
* @param type 检测类型,0为键,1为值
* @returns {boolean}
* @private
*/
function _testExternal(reg, type) {
var external = win.external || {};
for (var i in external) {
if (reg.test(type ? external[i] : i)) {
return true;
}
}
return false;
}
/**
* 获取 Chromium 内核浏览器类型
* @link http://www.adtchrome.com/js/help.js
* @link https://ext.chrome.360.cn/webstore
* @link https://ext.se.360.cn
* @return {String}
* 360ee 360极速浏览器
* 360se 360安全浏览器
* sougou 搜狗浏览器
* liebao 猎豹浏览器
* chrome 谷歌浏览器
* '' 无法判断
* @version 1.0
* 2014年3月12日20:39:55
*/
function _getChromiumType() {
if (isIe || typeof win.scrollMaxX !== 'undefined' || REG_APPLE.test(nav.vendor || '')) {
return '';
}
if (regEdge.test(navigator.userAgent)) {
return 'Edge';
}
var _track = 'track' in document.createElement('track');//chrome下为true,ie下为false
var webstoreKeysLength = win.chrome && win.chrome.webstore ? Object.keys(win.chrome.webstore).length : 0;
var chromeAppKeysLength = win.chrome && win.chrome.app ? Object.keys(win.chrome.app).length : 0;//360se=6 360ee=5
// 搜狗浏览器
if (_testExternal(/^sogou/i, 0)) {
return 'sogou';
}
// 猎豹浏览器
if (_testExternal(/^liebao/i, 0)) {
return 'liebao';
}
// chrome
if (win.clientInformation && win.clientInformation.languages && win.clientInformation.languages.length > 2) {
return 'chrome';
}
//注意此方法只能判断急速模式下的浏览器类型
if (_track) {
// 360极速浏览器|360安全浏览器
// return webstoreKeysLength > 1 ? '360ee' : '360se';//截止20170405已经失效 此方法不能判断安全与急速
// return chromeAppKeysLength > 5 ? '360ee' : '360se';//通过app下的keys个数判断
return Object.keys(window.chrome.app).join().indexOf("getDetailsForFrame") > -1 ? '360ee' : '360se';//通过360se下有'getDetailsForFrame'特殊方法判断
}
return '';
}
// 获得ie浏览器版本
function _getIeVersion() {
var v = 3,
p = document.createElement('p'),
all = p.getElementsByTagName('i');
while (
p.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
all[0]);
return v > 4 ? v : 0;
}
//获得chrome浏览器版本
function _getChromeVersion() {
var ua = navigator.userAgent;
var v = regChromeVersion.exec(ua);
return v[v.length - 1];
}
return {
isIE: function () {
return !!ieVer;
},
ieVersion: function () {
return ieVer;
},
isEdge: function () {
return chromiumType === 'Edge';
},
isChrome: function () {
return chromiumType === 'chrome';
},
chromeVersion: function () {
return _getChromeVersion();
},
is360se: function () {
return chromiumType === '360se';
},
is360ee: function () {
return chromiumType === '360ee';
},
isLiebao: function () {
return chromiumType === 'liebao';
},
isSogou: function () {
return chromiumType === 'sogou';
},
isQQ: function () {
return chromiumType === 'qq';
}
}
}
function getUserAgentInfoToString() {
var shell = getUserAgentInfoFoo();
if (shell.isIE()) {
return "IE:" + shell.ieVersion();
}
if (shell.isEdge()) {
return 'Edge'
}
if (shell.isChrome()) {
return 'chrome:' + shell.chromeVersion();
}
if (shell.is360se()) {
return '360se'
}
if (shell.is360ee()) {
return '360ee'
}
if (shell.isLiebao()) {
return 'liebao'
}
if (shell.isSogou()) {
return 'sogou'
}
if (shell.isQQ()) {
return 'qq'
}
return ''
}
// /**
// * 测试 MIME
// * @param where
// * @param value
// * @param [name]
// * @param [nameReg]
// * @returns {boolean}
// * @private
// */
// function _mime(where, value, name, nameReg) {
// var mimeTypes = navigator.mimeTypes;
// var i;
//
// for (i in mimeTypes) {
// if (mimeTypes[i][where] == value) {
// if (name !== undefined && nameReg.test(mimeTypes[i][name])) {
// return true;
// }
// else if (name === undefined) {
// return true;
// }
// }
// }
//
// return false;
// }