userAgent
last update:
2020/12/19
// ../lib/userAgent.js
export const userAgent = () => {
const raw = window.navigator.userAgent;
const ua = {};
let deviceType;
let osType;
// sp
if (/iPhone/.test(raw) || /iPod/.test(raw)) {
deviceType = 'sp';
osType = 'ios';
} else if (/Android/.test(raw) && /Mobile/.test(raw)) {
deviceType = 'sp';
osType = 'android';
} else if (/Windows/.test(raw) && /Phone/.test(raw)) {
deviceType = 'sp';
} else if (/Firefox/.test(raw) && /Mobile/.test(raw)) {
deviceType = 'sp';
} else if (/BlackBerry/.test(raw) || /BB10/.test(raw)) {
deviceType = 'sp';
} else if (/Nokia/.test(raw)) {
deviceType = 'sp';
// tablet
} else if (/iPad/.test(raw)) {
deviceType = 'tablet';
osType = 'ios';
} else if (/Macintosh/.test(raw) && 'ontouchend' in document) {
deviceType = 'tablet';
osType = 'ipados';
} else if (/Android/.test(raw) && !/Mobile/.test(raw)) {
deviceType = 'tablet';
osType = 'android';
} else if (/Windows/.test(raw) && /Touch/.test(raw) && !/Tablet PC/.test(raw)) {
deviceType = 'tablet';
} else if (/Firefox/.test(raw) && /Tablet/.test(raw)) {
deviceType = 'tablet';
} else if (/Playbook/.test(raw)) {
deviceType = 'tablet';
} else if (/Kindle/.test(raw) || /Silk/.test(raw)) {
deviceType = 'tablet';
// pc
} else {
deviceType = 'pc';
if (/Mac/.test(raw)) {
osType = 'mac';
} else if (/Windows/.test(raw)) {
osType = 'win';
} else {
osType = 'unknown';
}
}
ua.raw = raw;
ua.deviceType = deviceType;
ua.osType = osType;
ua.isMs = deviceType === 'pc' && /Windows NT/.test(raw) && (!/Chrome/.test(raw) || /Firefox/.test(raw)); // ie or edge
ua.isMac = osType === 'mac';
ua.isWin = osType === 'win';
ua.isIos = osType === 'ios';
ua.isIpados = osType === 'ipados';
ua.isAndroid = osType === 'android';
ua.isPc = deviceType === 'pc';
ua.isSp = deviceType === 'sp';
ua.isTablet = deviceType === 'tablet';
return ua;
};
code_popup
import {userAgent} from '../lib/userAgent';
const ua = userAgent();
code_popup