forked from zhihu/griffith
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
48 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
export const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) | ||
|
||
export const isAndroid = /(android)/i.test(navigator.userAgent) | ||
export function parseUA(userAgent: string) { | ||
return { | ||
isIE: /MSIE|Trident/i.test(userAgent), | ||
isMobile: /iPhone|iPad|iPod|Android/i.test(userAgent), | ||
isAndroid: /(android)/i.test(userAgent), | ||
isSafari: /^((?!chrome|android).)*safari/i.test(userAgent), | ||
} | ||
} | ||
|
||
export const isSafari = /^((?!chrome|android).)*safari/i.test( | ||
navigator.userAgent | ||
export default parseUA( | ||
// TODO: 加一个 context 让各处访问更好 | ||
typeof navigator !== 'undefined' ? navigator.userAgent : '' | ||
) | ||
|
||
export default { | ||
isMobile, | ||
isAndroid, | ||
isSafari, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default function parseUA(userAgent: string) { | ||
return { | ||
isIE: /MSIE|Trident/i.test(userAgent), | ||
isMobile: /iPhone|iPad|iPod|Android/i.test(userAgent), | ||
isAndroid: /(android)/i.test(userAgent), | ||
isSafari: /^((?!chrome|android).)*safari/i.test(userAgent), | ||
} | ||
} |