artalk 2.2.3 → 2.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,222 @@
1
+ const win = (window as any) || {}
2
+ const nav = navigator || {}
3
+
4
+ function Detect (userAgent?: string) {
5
+ const u = String(userAgent || nav.userAgent)
6
+ const dest = {
7
+ os: '',
8
+ osVersion: '',
9
+ engine: '',
10
+ browser: '',
11
+ device: '',
12
+ language: '',
13
+ version: ''
14
+ }
15
+
16
+ // 内核
17
+ const engineMatch = {
18
+ Trident: u.includes('Trident') || u.includes('NET CLR'),
19
+ Presto: u.includes('Presto'),
20
+ WebKit: u.includes('AppleWebKit'),
21
+ Gecko: u.includes('Gecko/')
22
+ }
23
+
24
+ // 浏览器
25
+ const browserMatch = {
26
+ Safari: u.includes('Safari'),
27
+ Chrome: u.includes('Chrome') || u.includes('CriOS'),
28
+ IE: u.includes('MSIE') || u.includes('Trident'),
29
+ Edge: u.includes('Edge') || u.includes('Edg'),
30
+ Firefox: u.includes('Firefox') || u.includes('FxiOS'),
31
+ 'Firefox Focus': u.includes('Focus'),
32
+ Chromium: u.includes('Chromium'),
33
+ Opera: u.includes('Opera') || u.includes('OPR'),
34
+ Vivaldi: u.includes('Vivaldi'),
35
+ Yandex: u.includes('YaBrowser'),
36
+ Kindle: u.includes('Kindle') || u.includes('Silk/'),
37
+ 360: u.includes('360EE') || u.includes('360SE'),
38
+ UC: u.includes('UC') || u.includes(' UBrowser'),
39
+ QQBrowser: u.includes('QQBrowser'),
40
+ QQ: u.includes('QQ/'),
41
+ Baidu: u.includes('Baidu') || u.includes('BIDUBrowser'),
42
+ Maxthon: u.includes('Maxthon'),
43
+ Sogou: u.includes('MetaSr') || u.includes('Sogou'),
44
+ LBBROWSER: u.includes('LBBROWSER'),
45
+ '2345Explorer': u.includes('2345Explorer'),
46
+ TheWorld: u.includes('TheWorld'),
47
+ MIUI: u.includes('MiuiBrowser'),
48
+ Quark: u.includes('Quark'),
49
+ Qiyu: u.includes('Qiyu'),
50
+ Wechat: u.includes('MicroMessenger'),
51
+ Taobao: u.includes('AliApp(TB'),
52
+ Alipay: u.includes('AliApp(AP'),
53
+ Weibo: u.includes('Weibo'),
54
+ Douban: u.includes('com.douban.frodo'),
55
+ Suning: u.includes('SNEBUY-APP'),
56
+ iQiYi: u.includes('IqiyiApp'),
57
+ }
58
+
59
+ // 系统或平台
60
+ const osMatch = {
61
+ Windows: u.includes('Windows'),
62
+ Linux: u.includes('Linux') || u.includes('X11'),
63
+ 'macOS': u.includes('Macintosh'),
64
+ Android: u.includes('Android') || u.includes('Adr'),
65
+ Ubuntu: u.includes('Ubuntu'),
66
+ FreeBSD: u.includes('FreeBSD'),
67
+ Debian: u.includes('Debian'),
68
+ 'Windows Phone': u.includes('IEMobile') || u.includes('Windows Phone'),
69
+ BlackBerry: u.includes('BlackBerry') || u.includes('RIM'),
70
+ MeeGo: u.includes('MeeGo'),
71
+ Symbian: u.includes('Symbian'),
72
+ iOS: u.includes('like Mac OS X'),
73
+ 'Chrome OS': u.includes('CrOS'),
74
+ WebOS: u.includes('hpwOS'),
75
+ }
76
+
77
+ // 设备
78
+ const deviceMatch = {
79
+ Mobile: u.includes('Mobi') || u.includes('iPh') || u.includes('480'),
80
+ Tablet: u.includes('Tablet') || u.includes('Pad') || u.includes('Nexus 7')
81
+ }
82
+
83
+ // 修正
84
+ if (deviceMatch.Mobile) {
85
+ deviceMatch.Mobile = !(u.includes('iPad'))
86
+ } else if (browserMatch.Chrome && u.includes('Edg')) {
87
+ // Chrome 内核的 Edge
88
+ browserMatch.Chrome = false
89
+ browserMatch.Edge = true
90
+ } else if (win.showModalDialog && win.chrome) {
91
+ browserMatch.Chrome = false
92
+ browserMatch['360'] = true
93
+ }
94
+
95
+ // 默认设备
96
+ dest.device = 'PC'
97
+
98
+ // 语言
99
+ dest.language = (() => {
100
+ const g = ((nav as any).browserLanguage || nav.language)
101
+ const arr = g.split('-')
102
+ if (arr[1]) arr[1] = arr[1].toUpperCase()
103
+ return arr.join('_')
104
+ })()
105
+
106
+ // 应用判断数据
107
+ const hash = {
108
+ engine: engineMatch,
109
+ browser: browserMatch,
110
+ os: osMatch,
111
+ device: deviceMatch,
112
+ }
113
+ Object.entries(hash).forEach(([type, match]) => {
114
+ Object.entries(match).forEach(([name, result]) => {
115
+ if (result === true) dest[type] = name
116
+ })
117
+ })
118
+
119
+ // 系统版本信息
120
+ const osVersion = {
121
+ Windows: () => {
122
+ const v = u.replace(/^.*Windows NT ([\d.]+);.*$/, '$1')
123
+ const wvHash = {
124
+ '6.4': '10',
125
+ '6.3': '8.1',
126
+ '6.2': '8',
127
+ '6.1': '7',
128
+ '6.0': 'Vista',
129
+ '5.2': 'XP',
130
+ '5.1': 'XP',
131
+ '5.0': '2000',
132
+ '10.0': '10',
133
+ '11.0': '11' // 自定的,不是微软官方的判断方法
134
+ }
135
+ return wvHash[v] || v
136
+ },
137
+ Android: () => u.replace(/^.*Android ([\d.]+);.*$/, '$1'),
138
+ iOS: () => u.replace(/^.*OS ([\d_]+) like.*$/, '$1').replace(/_/g, '.'),
139
+ Debian: () => u.replace(/^.*Debian\/([\d.]+).*$/, '$1'),
140
+ 'Windows Phone': () => u.replace(/^.*Windows Phone( OS)? ([\d.]+);.*$/, '$2'),
141
+ 'macOS': () => u.replace(/^.*Mac OS X ([\d_]+).*$/, '$1').replace(/_/g, '.'),
142
+ WebOS: () => u.replace(/^.*hpwOS\/([\d.]+);.*$/, '$1')
143
+ }
144
+
145
+ dest.osVersion = ''
146
+ if (osVersion[dest.os]) {
147
+ dest.osVersion = osVersion[dest.os]()
148
+ if (dest.osVersion === u) {
149
+ dest.osVersion = ''
150
+ }
151
+ }
152
+
153
+ // 浏览器版本信息
154
+ const version = {
155
+ Safari: () => u.replace(/^.*Version\/([\d.]+).*$/, '$1'),
156
+ Chrome: () => u.replace(/^.*Chrome\/([\d.]+).*$/, '$1').replace(/^.*CriOS\/([\d.]+).*$/, '$1'),
157
+ IE: () => u.replace(/^.*MSIE ([\d.]+).*$/, '$1').replace(/^.*rv:([\d.]+).*$/, '$1'),
158
+ Edge: () => u.replace(/^.*(Edge|Edg|Edg[A-Z]{1})\/([\d.]+).*$/, '$2'),
159
+ Firefox: () => u.replace(/^.*Firefox\/([\d.]+).*$/, '$1').replace(/^.*FxiOS\/([\d.]+).*$/, '$1'),
160
+ 'Firefox Focus': () => u.replace(/^.*Focus\/([\d.]+).*$/, '$1'),
161
+ Chromium: () => u.replace(/^.*Chromium\/([\d.]+).*$/, '$1'),
162
+ Opera: () => u.replace(/^.*Opera\/([\d.]+).*$/, '$1').replace(/^.*OPR\/([\d.]+).*$/, '$1'),
163
+ Vivaldi: () => u.replace(/^.*Vivaldi\/([\d.]+).*$/, '$1'),
164
+ Yandex: () => u.replace(/^.*YaBrowser\/([\d.]+).*$/, '$1'),
165
+ Kindle: () => u.replace(/^.*Version\/([\d.]+).*$/, '$1'),
166
+ Maxthon: () => u.replace(/^.*Maxthon\/([\d.]+).*$/, '$1'),
167
+ QQBrowser: () => u.replace(/^.*QQBrowser\/([\d.]+).*$/, '$1'),
168
+ QQ: () => u.replace(/^.*QQ\/([\d.]+).*$/, '$1'),
169
+ Baidu: () => u.replace(/^.*BIDUBrowser[\s/]([\d.]+).*$/, '$1'),
170
+ UC: () => u.replace(/^.*UC?Browser\/([\d.]+).*$/, '$1'),
171
+ Sogou: () => u.replace(/^.*SE ([\d.X]+).*$/, '$1').replace(/^.*SogouMobileBrowser\/([\d.]+).*$/, '$1'),
172
+ '2345Explorer': () => u.replace(/^.*2345Explorer\/([\d.]+).*$/, '$1'),
173
+ TheWorld: () => u.replace(/^.*TheWorld ([\d.]+).*$/, '$1'),
174
+ MIUI: () => u.replace(/^.*MiuiBrowser\/([\d.]+).*$/, '$1'),
175
+ Quark: () => u.replace(/^.*Quark\/([\d.]+).*$/, '$1'),
176
+ Qiyu: () => u.replace(/^.*Qiyu\/([\d.]+).*$/, '$1'),
177
+ Wechat: () => u.replace(/^.*MicroMessenger\/([\d.]+).*$/, '$1'),
178
+ Taobao: () => u.replace(/^.*AliApp\(TB\/([\d.]+).*$/, '$1'),
179
+ Alipay: () => u.replace(/^.*AliApp\(AP\/([\d.]+).*$/, '$1'),
180
+ Weibo: () => u.replace(/^.*weibo__([\d.]+).*$/, '$1'),
181
+ Douban: () => u.replace(/^.*com.douban.frodo\/([\d.]+).*$/, '$1'),
182
+ Suning: () => u.replace(/^.*SNEBUY-APP([\d.]+).*$/, '$1'),
183
+ iQiYi: () => u.replace(/^.*IqiyiVersion\/([\d.]+).*$/, '$1'),
184
+ }
185
+
186
+ dest.version = ''
187
+ if (version[dest.browser]) {
188
+ dest.version = version[dest.browser]()
189
+ if (dest.version === u) {
190
+ dest.version = ''
191
+ }
192
+ }
193
+
194
+ // 简化版本号
195
+ /* if (_this.osVersion.indexOf('.')) {
196
+ _this.osVersion = _this.osVersion.substring(0, _this.osVersion.indexOf('.'))
197
+ } */
198
+ if (dest.version.indexOf('.')) {
199
+ dest.version = dest.version.substring(0, dest.version.indexOf('.'))
200
+ }
201
+
202
+ // 修正
203
+ if (dest.os === 'iOS' && u.includes('iPad')) {
204
+ dest.os = 'iPadOS'
205
+ } else if (dest.browser === 'Edge' && !u.includes('Edg')) {
206
+ dest.engine = 'EdgeHTML'
207
+ } else if (dest.browser === 'MIUI') {
208
+ dest.os = 'Android'
209
+ } else if (dest.browser === 'Chrome' && Number(dest.version) > 27) {
210
+ dest.engine = 'Blink'
211
+ } else if (dest.browser === 'Opera' && Number(dest.version) > 12) {
212
+ dest.engine = 'Blink'
213
+ } else if (dest.browser === 'Yandex') {
214
+ dest.engine = 'Blink'
215
+ } else if (dest.browser === undefined) {
216
+ dest.browser = 'Unknow App'
217
+ }
218
+
219
+ return dest
220
+ }
221
+
222
+ export default Detect
package/src/lib/utils.ts CHANGED
@@ -143,10 +143,10 @@ export function versionCompare(a: string, b: string) {
143
143
  /** 初始化 marked */
144
144
  export function initMarked(ctx: Context) {
145
145
  const renderer = new libMarked.Renderer()
146
- const linkRenderer = renderer.link
146
+ const orgLinkRenderer = renderer.link
147
147
  renderer.link = (href, title, text) => {
148
148
  const localLink = href?.startsWith(`${window.location.protocol}//${window.location.hostname}`);
149
- const html = linkRenderer.call(renderer as any, href, title, text);
149
+ const html = orgLinkRenderer.call(renderer as any, href, title, text);
150
150
  return html.replace(/^<a /, `<a target="_blank" ${!localLink ? `rel="noreferrer noopener nofollow"` : ''} `);
151
151
  }
152
152
 
@@ -186,8 +186,9 @@ export function initMarked(ctx: Context) {
186
186
 
187
187
  /** 解析 markdown */
188
188
  export function marked(ctx: Context, src: string): string {
189
+ // @link https://github.com/markedjs/marked/discussions/1232
189
190
  // @link https://gist.github.com/lionel-rowe/bb384465ba4e4c81a9c8dada84167225
190
- return insane(ctx.markedInstance.parse(src), {
191
+ let dest = insane(ctx.markedInstance.parse(src), {
191
192
  allowedClasses: {},
192
193
  allowedSchemes: ['http', 'https', 'mailto'],
193
194
  allowedTags: [
@@ -198,7 +199,7 @@ export function marked(ctx: Context, src: string): string {
198
199
  ],
199
200
  allowedAttributes: {
200
201
  '*': ['title', 'accesskey'],
201
- a: ['href', 'name', 'target', 'aria-label'],
202
+ a: ['href', 'name', 'target', 'aria-label', 'rel'],
202
203
  img: ['src', 'alt', 'title', 'atk-emoticon', 'aria-label'],
203
204
  // for code highlight
204
205
  code: ['class'],
@@ -229,28 +230,45 @@ export function marked(ctx: Context, src: string): string {
229
230
  return true
230
231
  }
231
232
  })
233
+
234
+ // 内容替换器
235
+ ctx.markedReplacers.forEach((replacer) => {
236
+ if (typeof replacer === 'function') dest = replacer(dest)
237
+ })
238
+
239
+ return dest
232
240
  }
233
241
 
234
242
  /** 获取修正后的 UserAgent */
235
243
  export async function getCorrectUserAgent() {
236
244
  const uaRaw = navigator.userAgent
237
- const uaData = (navigator as any).userAgentData // @link https://web.dev/migrate-to-ua-ch/
238
- if (!uaData || !uaData.getHighEntropyValues) {
245
+ if (!(navigator as any).userAgentData || !(navigator as any).userAgentData.getHighEntropyValues) {
239
246
  return uaRaw
240
247
  }
241
248
 
242
- // microsoft f******k you!!!!!
243
- // @link https://docs.microsoft.com/en-us/microsoft-edge/web-platform/how-to-detect-win11
249
+ // @link https://web.dev/migrate-to-ua-ch/
250
+ // @link https://web.dev/user-agent-client-hints/
251
+ const uaData = (navigator as any).userAgentData
244
252
  let uaGot: any = null
245
253
  try {
246
254
  uaGot = await uaData.getHighEntropyValues(["platformVersion"])
247
255
  } catch (err) { console.error(err); return uaRaw }
248
-
249
- if (uaData.platform !== "Windows") { return uaRaw }
250
256
  const majorPlatformVersion = Number(uaGot.platformVersion.split('.')[0])
251
- if (majorPlatformVersion >= 13) {
252
- // Win11 样本:"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36"
253
- return uaRaw.replace(/Windows\W+NT\W+10.0/, 'Windows NT 11.0')
257
+
258
+ if (uaData.platform === "Windows") {
259
+ if (majorPlatformVersion >= 13) { // @link https://docs.microsoft.com/en-us/microsoft-edge/web-platform/how-to-detect-win11
260
+ // @date 2022-4-29
261
+ // Win 11 样本:"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36"
262
+ return uaRaw.replace(/Windows NT 10.0/, 'Windows NT 11.0')
263
+ }
264
+ }
265
+ if (uaData.platform === "macOS") {
266
+ if (majorPlatformVersion >= 11) { // 11 => BigSur
267
+ // @date 2022-4-29
268
+ // (Intel Chip) macOS 12.3 样本:"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36"
269
+ // (Arm Chip) macOS 样本:"Mozilla/5.0 (Macintosh; ARM Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.2 Safari/605.1.15"
270
+ return uaRaw.replace(/(Mac OS X \d+_\d+_\d+|Mac OS X)/, `Mac OS X ${uaGot.platformVersion.replace(/\./g, '_')}`)
271
+ }
254
272
  }
255
273
 
256
274
  return uaRaw
@@ -268,7 +286,7 @@ export function isValidURL(urlRaw: string) {
268
286
 
269
287
  /** 获取基于 conf.server 的 URL */
270
288
  export function getURLBasedOnApi(ctx: Context, path: string) {
271
- return `${ctx.conf.server.replace(/\/api\/?$/, '')}/${path.replace(/^\//, '')}`
289
+ return getURLBasedOn(ctx.conf.server, path)
272
290
  }
273
291
 
274
292
  /** 获取基于某个 baseURL 的 URL */
@@ -167,6 +167,7 @@
167
167
  border-left: 3px solid #eee;
168
168
  margin-bottom: 10px;
169
169
  position: relative;
170
+ margin-top: 10px;
170
171
 
171
172
  .atk-meta {
172
173
  font-size: 15px;
@@ -19,9 +19,11 @@
19
19
 
20
20
  input, textarea, button, optgroup, select {
21
21
  font-family: inherit;
22
+ color: inherit;
23
+ font-size: inherit;
22
24
  }
23
25
 
24
- @codeFont: Source Code Pro,courier new,Input Mono,PT Mono,SFMono-Regular,Consolas,Monaco,Menlo,PingFang SC,Liberation Mono,Microsoft YaHei,Courier,monospace;
26
+ @codeFont: source code pro, Consolas, Monaco, Menlo, sans-serif;
25
27
 
26
28
  code {
27
29
  font-family: @codeFont;
@@ -33,8 +35,8 @@
33
35
  }
34
36
 
35
37
  pre {
36
- margin-top: 10px;
37
- margin-bottom: 0;
38
+ margin: 10px 0 0 0;
39
+ padding: 0;
38
40
  line-height: 0;
39
41
  }
40
42
 
@@ -196,6 +198,9 @@
196
198
  .atk-fade-out {
197
199
  animation: atkFadeOut both .2s;
198
200
  }
201
+ .atk-rotate {
202
+ animation: atkRotate 2s linear infinite;
203
+ }
199
204
 
200
205
  @keyframes atkFadeIn {
201
206
  0% { opacity: 0 }
@@ -207,6 +212,11 @@
207
212
  0% {}
208
213
  }
209
214
 
215
+ @keyframes atkRotate {
216
+ from { transform: rotate(0deg); }
217
+ to { transform: rotate(360deg); }
218
+ }
219
+
210
220
  i.atk-icon {
211
221
  width: 20px;
212
222
  height: 20px;
@@ -215,6 +225,7 @@ i.atk-icon {
215
225
  background-repeat: no-repeat;
216
226
  mask-repeat: no-repeat;
217
227
  mask-position: center;
228
+ mask-size: contain;
218
229
  }
219
230
 
220
231
  .atk-icon-sync {
@@ -1,6 +1,6 @@
1
1
  export default interface ArtalkConfig {
2
2
  /** 装载元素 */
3
- el: string
3
+ el: string|HTMLElement
4
4
 
5
5
  /** 页面唯一标识(完整 URL) */
6
6
  pageKey: string
package/types/event.d.ts CHANGED
@@ -19,7 +19,7 @@ export interface EventPayloadMap {
19
19
  'list-refresh-ui': undefined // 刷新 List UI
20
20
 
21
21
  // Sidebar
22
- 'sidebar-show': undefined // 侧边栏显示
22
+ 'sidebar-show': SidebarShowPayload // 侧边栏显示
23
23
  'sidebar-hide': undefined // 侧边栏隐藏
24
24
 
25
25
  // Editor
@@ -70,6 +70,10 @@ export interface EditorReplyPayload {
70
70
  scroll?: boolean
71
71
  }
72
72
 
73
+ export interface SidebarShowPayload {
74
+ view?: 'comments'|'sites'|'pages'|'transfer'|string
75
+ }
76
+
73
77
  // ============================================
74
78
  export interface Handler<P> {
75
79
  (payload: P): void
package/src/lib/detect.js DELETED
@@ -1,263 +0,0 @@
1
- /* eslint-disable */
2
- var win = window || {}
3
- var nav = navigator || {}
4
- function Detect (userAgent) {
5
- var u = userAgent || nav.userAgent
6
- var _this = this
7
-
8
- var match = {
9
- // 内核
10
- Trident: u.indexOf('Trident') > -1 || u.indexOf('NET CLR') > -1,
11
- Presto: u.indexOf('Presto') > -1,
12
- WebKit: u.indexOf('AppleWebKit') > -1,
13
- Gecko: u.indexOf('Gecko/') > -1,
14
- // 浏览器
15
- Safari: u.indexOf('Safari') > -1,
16
- Chrome: u.indexOf('Chrome') > -1 || u.indexOf('CriOS') > -1,
17
- IE: u.indexOf('MSIE') > -1 || u.indexOf('Trident') > -1,
18
- Edge: u.indexOf('Edge') > -1,
19
- Firefox: u.indexOf('Firefox') > -1 || u.indexOf('FxiOS') > -1,
20
- 'Firefox Focus': u.indexOf('Focus') > -1,
21
- Chromium: u.indexOf('Chromium') > -1,
22
- Opera: u.indexOf('Opera') > -1 || u.indexOf('OPR') > -1,
23
- Vivaldi: u.indexOf('Vivaldi') > -1,
24
- Yandex: u.indexOf('YaBrowser') > -1,
25
- Kindle: u.indexOf('Kindle') > -1 || u.indexOf('Silk/') > -1,
26
- 360: u.indexOf('360EE') > -1 || u.indexOf('360SE') > -1,
27
- UC: u.indexOf('UC') > -1 || u.indexOf(' UBrowser') > -1,
28
- QQBrowser: u.indexOf('QQBrowser') > -1,
29
- QQ: u.indexOf('QQ/') > -1,
30
- Baidu: u.indexOf('Baidu') > -1 || u.indexOf('BIDUBrowser') > -1,
31
- Maxthon: u.indexOf('Maxthon') > -1,
32
- Sogou: u.indexOf('MetaSr') > -1 || u.indexOf('Sogou') > -1,
33
- LBBROWSER: u.indexOf('LBBROWSER') > -1,
34
- '2345Explorer': u.indexOf('2345Explorer') > -1,
35
- TheWorld: u.indexOf('TheWorld') > -1,
36
- XiaoMi: u.indexOf('MiuiBrowser') > -1,
37
- Quark: u.indexOf('Quark') > -1,
38
- Qiyu: u.indexOf('Qiyu') > -1,
39
- Wechat: u.indexOf('MicroMessenger') > -1,
40
- Taobao: u.indexOf('AliApp(TB') > -1,
41
- Alipay: u.indexOf('AliApp(AP') > -1,
42
- Weibo: u.indexOf('Weibo') > -1,
43
- Douban: u.indexOf('com.douban.frodo') > -1,
44
- Suning: u.indexOf('SNEBUY-APP') > -1,
45
- iQiYi: u.indexOf('IqiyiApp') > -1,
46
- // 系统或平台
47
- Windows: u.indexOf('Windows') > -1,
48
- Linux: u.indexOf('Linux') > -1 || u.indexOf('X11') > -1,
49
- 'Mac OS': u.indexOf('Macintosh') > -1,
50
- Android: u.indexOf('Android') > -1 || u.indexOf('Adr') > -1,
51
- Ubuntu: u.indexOf('Ubuntu') > -1,
52
- FreeBSD: u.indexOf('FreeBSD') > -1,
53
- Debian: u.indexOf('Debian') > -1,
54
- 'Windows Phone': u.indexOf('IEMobile') > -1 || u.indexOf('Windows Phone') > -1,
55
- BlackBerry: u.indexOf('BlackBerry') > -1 || u.indexOf('RIM') > -1,
56
- MeeGo: u.indexOf('MeeGo') > -1,
57
- Symbian: u.indexOf('Symbian') > -1,
58
- iOS: u.indexOf('like Mac OS X') > -1,
59
- 'Chrome OS': u.indexOf('CrOS') > -1,
60
- WebOS: u.indexOf('hpwOS') > -1,
61
- // 设备
62
- Mobile: u.indexOf('Mobi') > -1 || u.indexOf('iPh') > -1 || u.indexOf('480') > -1,
63
- Tablet: u.indexOf('Tablet') > -1 || u.indexOf('Pad') > -1 || u.indexOf('Nexus 7') > -1
64
- }
65
- // 修正
66
- if (match.Mobile) {
67
- match.Mobile = !(u.indexOf('iPad') > -1)
68
- } else if (win.showModalDialog && win.chrome) {
69
- match['360'] = true
70
- }
71
- // 基本信息
72
- var hash = {
73
- engine: ['WebKit', 'Trident', 'Gecko', 'Presto'],
74
- browser: ['Safari', 'Chrome', 'Edge', 'IE', 'Firefox', 'Firefox Focus', 'Chromium', 'Opera', 'Vivaldi', 'Yandex', 'Kindle', '360', 'UC', 'QQBrowser', 'QQ', 'Baidu', 'Maxthon', 'Sogou', 'LBBROWSER', '2345Explorer', 'TheWorld', 'XiaoMi', 'Quark', 'Qiyu', 'Wechat', 'Taobao', 'Alipay', 'Weibo', 'Douban', 'Suning', 'iQiYi'],
75
- os: ['Windows', 'Linux', 'Mac OS', 'Android', 'Ubuntu', 'FreeBSD', 'Debian', 'iOS', 'Windows Phone', 'BlackBerry', 'MeeGo', 'Symbian', 'Chrome OS', 'WebOS'],
76
- device: ['Mobile', 'Tablet']
77
- }
78
- _this.device = 'PC'
79
- _this.language = (function () {
80
- var g = (nav.browserLanguage || nav.language)
81
- var arr = g.split('-')
82
- if (arr[1]) {
83
- arr[1] = arr[1].toUpperCase()
84
- }
85
- return arr.join('_')
86
- })()
87
- for (var s in hash) {
88
- for (var i = 0; i < hash[s].length; i++) {
89
- var value = hash[s][i]
90
- if (match[value]) {
91
- _this[s] = value
92
- }
93
- }
94
- }
95
- // 系统版本信息
96
- var osVersion = {
97
- Windows: function () {
98
- var v = u.replace(/^.*Windows NT ([\d.]+);.*$/, '$1')
99
- var hash = {
100
- 6.4: '10',
101
- 6.3: '8.1',
102
- 6.2: '8',
103
- 6.1: '7',
104
- '6.0': 'Vista',
105
- 5.2: 'XP',
106
- 5.1: 'XP',
107
- '5.0': '2000',
108
- '10.0': '10',
109
- '11.0': '11' // 自定的,不是微软官方的判断方法
110
- }
111
- return hash[v] || v
112
- },
113
- Android: function () {
114
- return u.replace(/^.*Android ([\d.]+);.*$/, '$1')
115
- },
116
- iOS: function () {
117
- return u.replace(/^.*OS ([\d_]+) like.*$/, '$1').replace(/_/g, '.')
118
- },
119
- Debian: function () {
120
- return u.replace(/^.*Debian\/([\d.]+).*$/, '$1')
121
- },
122
- 'Windows Phone': function () {
123
- return u.replace(/^.*Windows Phone( OS)? ([\d.]+);.*$/, '$2')
124
- },
125
- 'Mac OS': function () {
126
- return u.replace(/^.*Mac OS X ([\d_]+).*$/, '$1').replace(/_/g, '.')
127
- },
128
- WebOS: function () {
129
- return u.replace(/^.*hpwOS\/([\d.]+);.*$/, '$1')
130
- }
131
- }
132
- _this.osVersion = ''
133
- if (osVersion[_this.os]) {
134
- _this.osVersion = osVersion[_this.os]()
135
- if (_this.osVersion === u) {
136
- _this.osVersion = ''
137
- }
138
- }
139
- // 浏览器版本信息
140
- var version = {
141
- Safari: function () {
142
- return u.replace(/^.*Version\/([\d.]+).*$/, '$1')
143
- },
144
- Chrome: function () {
145
- return u.replace(/^.*Chrome\/([\d.]+).*$/, '$1').replace(/^.*CriOS\/([\d.]+).*$/, '$1')
146
- },
147
- IE: function () {
148
- return u.replace(/^.*MSIE ([\d.]+).*$/, '$1').replace(/^.*rv:([\d.]+).*$/, '$1')
149
- },
150
- Edge: function () {
151
- return u.replace(/^.*Edge\/([\d.]+).*$/, '$1')
152
- },
153
- Firefox: function () {
154
- return u.replace(/^.*Firefox\/([\d.]+).*$/, '$1').replace(/^.*FxiOS\/([\d.]+).*$/, '$1')
155
- },
156
- 'Firefox Focus': function () {
157
- return u.replace(/^.*Focus\/([\d.]+).*$/, '$1')
158
- },
159
- Chromium: function () {
160
- return u.replace(/^.*Chromium\/([\d.]+).*$/, '$1')
161
- },
162
- Opera: function () {
163
- return u.replace(/^.*Opera\/([\d.]+).*$/, '$1').replace(/^.*OPR\/([\d.]+).*$/, '$1')
164
- },
165
- Vivaldi: function () {
166
- return u.replace(/^.*Vivaldi\/([\d.]+).*$/, '$1')
167
- },
168
- Yandex: function () {
169
- return u.replace(/^.*YaBrowser\/([\d.]+).*$/, '$1')
170
- },
171
- Kindle: function () {
172
- return u.replace(/^.*Version\/([\d.]+).*$/, '$1')
173
- },
174
- Maxthon: function () {
175
- return u.replace(/^.*Maxthon\/([\d.]+).*$/, '$1')
176
- },
177
- QQBrowser: function () {
178
- return u.replace(/^.*QQBrowser\/([\d.]+).*$/, '$1')
179
- },
180
- QQ: function () {
181
- return u.replace(/^.*QQ\/([\d.]+).*$/, '$1')
182
- },
183
- Baidu: function () {
184
- return u.replace(/^.*BIDUBrowser[\s/]([\d.]+).*$/, '$1')
185
- },
186
- UC: function () {
187
- return u.replace(/^.*UC?Browser\/([\d.]+).*$/, '$1')
188
- },
189
- Sogou: function () {
190
- return u.replace(/^.*SE ([\d.X]+).*$/, '$1').replace(/^.*SogouMobileBrowser\/([\d.]+).*$/, '$1')
191
- },
192
- '2345Explorer': function () {
193
- return u.replace(/^.*2345Explorer\/([\d.]+).*$/, '$1')
194
- },
195
- TheWorld: function () {
196
- return u.replace(/^.*TheWorld ([\d.]+).*$/, '$1')
197
- },
198
- XiaoMi: function () {
199
- return u.replace(/^.*MiuiBrowser\/([\d.]+).*$/, '$1')
200
- },
201
- Quark: function () {
202
- return u.replace(/^.*Quark\/([\d.]+).*$/, '$1')
203
- },
204
- Qiyu: function () {
205
- return u.replace(/^.*Qiyu\/([\d.]+).*$/, '$1')
206
- },
207
- Wechat: function () {
208
- return u.replace(/^.*MicroMessenger\/([\d.]+).*$/, '$1')
209
- },
210
- Taobao: function () {
211
- return u.replace(/^.*AliApp\(TB\/([\d.]+).*$/, '$1')
212
- },
213
- Alipay: function () {
214
- return u.replace(/^.*AliApp\(AP\/([\d.]+).*$/, '$1')
215
- },
216
- Weibo: function () {
217
- return u.replace(/^.*weibo__([\d.]+).*$/, '$1')
218
- },
219
- Douban: function () {
220
- return u.replace(/^.*com.douban.frodo\/([\d.]+).*$/, '$1')
221
- },
222
- Suning: function () {
223
- return u.replace(/^.*SNEBUY-APP([\d.]+).*$/, '$1')
224
- },
225
- iQiYi: function () {
226
- return u.replace(/^.*IqiyiVersion\/([\d.]+).*$/, '$1')
227
- }
228
- }
229
- _this.version = ''
230
- if (version[_this.browser]) {
231
- _this.version = version[_this.browser]()
232
- if (_this.version === u) {
233
- _this.version = ''
234
- }
235
- }
236
-
237
- // 简化版本号
238
- /* if (_this.osVersion.indexOf('.')) {
239
- _this.osVersion = _this.osVersion.substring(0, _this.osVersion.indexOf('.'))
240
- } */
241
- if (_this.version.indexOf('.')) {
242
- _this.version = _this.version.substring(0, _this.version.indexOf('.'))
243
- }
244
-
245
- // 修正
246
- if (_this.browser === 'Edge') {
247
- _this.engine = 'EdgeHTML'
248
- } else if (_this.browser === 'Chrome' && parseInt(_this.version) > 27) {
249
- _this.engine = 'Blink'
250
- } else if (_this.browser === 'Opera' && parseInt(_this.version) > 12) {
251
- _this.engine = 'Blink'
252
- } else if (_this.browser === 'Yandex') {
253
- _this.engine = 'Blink'
254
- } else if (_this.browser === undefined) {
255
- _this.browser = 'Unknow App'
256
- }
257
- };
258
-
259
- function detectFactory (u) {
260
- return new Detect(u)
261
- }
262
-
263
- export default detectFactory