2019-02-14 16:06:14 +00:00
|
|
|
import Utils from './utils.js';
|
2019-05-20 07:33:10 +00:00
|
|
|
import { PLATFORMS_MAP } from './constants.js';
|
2017-06-08 22:12:44 +00:00
|
|
|
|
2017-06-09 18:58:44 +00:00
|
|
|
/*
|
|
|
|
* Tablets go first since usually they have more specific
|
|
|
|
* signs to detect.
|
|
|
|
*/
|
|
|
|
|
2017-06-08 22:12:44 +00:00
|
|
|
export default [
|
2019-01-16 11:30:38 +00:00
|
|
|
/* Googlebot */
|
|
|
|
{
|
|
|
|
test: [/googlebot/i],
|
|
|
|
describe() {
|
|
|
|
return {
|
|
|
|
type: 'bot',
|
|
|
|
vendor: 'Google',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2018-12-30 07:03:08 +00:00
|
|
|
/* Huawei */
|
|
|
|
{
|
|
|
|
test: [/huawei/i],
|
|
|
|
describe(ua) {
|
2019-02-14 16:06:14 +00:00
|
|
|
const model = Utils.getFirstMatch(/(can-l01)/i, ua) && 'Nova';
|
2018-12-30 07:03:08 +00:00
|
|
|
const platform = {
|
2019-05-20 07:33:10 +00:00
|
|
|
type: PLATFORMS_MAP.mobile,
|
2018-12-30 08:18:58 +00:00
|
|
|
vendor: 'Huawei',
|
2018-12-30 07:03:08 +00:00
|
|
|
};
|
|
|
|
if (model) {
|
2018-12-30 08:18:58 +00:00
|
|
|
platform.model = model;
|
2018-12-30 07:03:08 +00:00
|
|
|
}
|
|
|
|
return platform;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2017-06-08 22:12:44 +00:00
|
|
|
/* Nexus Tablet */
|
|
|
|
{
|
2018-07-17 18:21:56 +00:00
|
|
|
test: [/nexus\s*(?:7|8|9|10).*/i],
|
2017-06-08 22:12:44 +00:00
|
|
|
describe() {
|
|
|
|
return {
|
2019-05-20 07:33:10 +00:00
|
|
|
type: PLATFORMS_MAP.tablet,
|
2017-06-08 22:12:44 +00:00
|
|
|
vendor: 'Nexus',
|
|
|
|
};
|
2017-12-20 21:29:06 +00:00
|
|
|
},
|
2017-06-08 22:12:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/* iPad */
|
|
|
|
{
|
|
|
|
test: [/ipad/i],
|
|
|
|
describe() {
|
|
|
|
return {
|
2019-05-20 07:33:10 +00:00
|
|
|
type: PLATFORMS_MAP.tablet,
|
2017-06-08 22:12:44 +00:00
|
|
|
vendor: 'Apple',
|
2017-12-20 21:29:06 +00:00
|
|
|
model: 'iPad',
|
|
|
|
};
|
|
|
|
},
|
2017-06-08 22:12:44 +00:00
|
|
|
},
|
|
|
|
|
2019-12-13 22:36:53 +00:00
|
|
|
/* Firefox on iPad */
|
|
|
|
{
|
2020-04-28 09:37:01 +00:00
|
|
|
test: [/Macintosh(.*?) FxiOS(.*?)\//],
|
2019-12-13 22:36:53 +00:00
|
|
|
describe() {
|
|
|
|
return {
|
|
|
|
type: PLATFORMS_MAP.tablet,
|
|
|
|
vendor: 'Apple',
|
|
|
|
model: 'iPad',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2017-06-09 19:08:48 +00:00
|
|
|
/* Amazon Kindle Fire */
|
|
|
|
{
|
|
|
|
test: [/kftt build/i],
|
|
|
|
describe() {
|
|
|
|
return {
|
2019-05-20 07:33:10 +00:00
|
|
|
type: PLATFORMS_MAP.tablet,
|
2017-06-09 19:08:48 +00:00
|
|
|
vendor: 'Amazon',
|
2017-12-20 21:29:06 +00:00
|
|
|
model: 'Kindle Fire HD 7',
|
|
|
|
};
|
|
|
|
},
|
2017-06-09 19:08:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/* Another Amazon Tablet with Silk */
|
2017-06-08 22:12:44 +00:00
|
|
|
{
|
|
|
|
test: [/silk/i],
|
|
|
|
describe() {
|
|
|
|
return {
|
2019-05-20 07:33:10 +00:00
|
|
|
type: PLATFORMS_MAP.tablet,
|
2017-12-20 21:29:06 +00:00
|
|
|
vendor: 'Amazon',
|
|
|
|
};
|
|
|
|
},
|
2017-06-08 22:12:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/* Tablet */
|
|
|
|
{
|
2019-09-06 11:27:16 +00:00
|
|
|
test: [/tablet(?! pc)/i],
|
2017-06-08 22:12:44 +00:00
|
|
|
describe() {
|
|
|
|
return {
|
2019-05-20 07:33:10 +00:00
|
|
|
type: PLATFORMS_MAP.tablet,
|
2017-06-08 22:12:44 +00:00
|
|
|
};
|
2017-12-20 21:29:06 +00:00
|
|
|
},
|
2017-06-08 22:12:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/* iPod/iPhone */
|
|
|
|
{
|
2017-06-09 20:49:08 +00:00
|
|
|
test(parser) {
|
|
|
|
const iDevice = parser.test(/ipod|iphone/i);
|
|
|
|
const likeIDevice = parser.test(/like (ipod|iphone)/i);
|
|
|
|
return iDevice && !likeIDevice;
|
|
|
|
},
|
2017-06-08 22:12:44 +00:00
|
|
|
describe(ua) {
|
2019-02-14 16:06:14 +00:00
|
|
|
const model = Utils.getFirstMatch(/(ipod|iphone)/i, ua);
|
2017-06-08 22:12:44 +00:00
|
|
|
return {
|
2019-05-20 07:33:10 +00:00
|
|
|
type: PLATFORMS_MAP.mobile,
|
2017-06-08 22:12:44 +00:00
|
|
|
vendor: 'Apple',
|
2017-12-20 21:29:06 +00:00
|
|
|
model,
|
2017-06-08 22:12:44 +00:00
|
|
|
};
|
2017-12-20 21:29:06 +00:00
|
|
|
},
|
2017-06-08 22:12:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/* Nexus Mobile */
|
|
|
|
{
|
2018-07-17 18:21:56 +00:00
|
|
|
test: [/nexus\s*[0-6].*/i, /galaxy nexus/i],
|
2017-06-08 22:12:44 +00:00
|
|
|
describe() {
|
|
|
|
return {
|
2019-05-20 07:33:10 +00:00
|
|
|
type: PLATFORMS_MAP.mobile,
|
2017-12-20 21:29:06 +00:00
|
|
|
vendor: 'Nexus',
|
2017-06-08 22:12:44 +00:00
|
|
|
};
|
2017-12-20 21:29:06 +00:00
|
|
|
},
|
2017-06-08 22:12:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/* Mobile */
|
|
|
|
{
|
|
|
|
test: [/[^-]mobi/i],
|
|
|
|
describe() {
|
|
|
|
return {
|
2019-05-20 07:33:10 +00:00
|
|
|
type: PLATFORMS_MAP.mobile,
|
2017-06-08 22:12:44 +00:00
|
|
|
};
|
2017-12-20 21:29:06 +00:00
|
|
|
},
|
2017-06-08 22:12:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/* BlackBerry */
|
|
|
|
{
|
|
|
|
test(parser) {
|
|
|
|
return parser.getBrowserName(true) === 'blackberry';
|
|
|
|
},
|
|
|
|
describe() {
|
|
|
|
return {
|
2019-05-20 07:33:10 +00:00
|
|
|
type: PLATFORMS_MAP.mobile,
|
2017-12-20 21:29:06 +00:00
|
|
|
vendor: 'BlackBerry',
|
2017-06-08 22:12:44 +00:00
|
|
|
};
|
2017-12-20 21:29:06 +00:00
|
|
|
},
|
2017-06-08 22:12:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/* Bada */
|
|
|
|
{
|
|
|
|
test(parser) {
|
|
|
|
return parser.getBrowserName(true) === 'bada';
|
|
|
|
},
|
|
|
|
describe() {
|
|
|
|
return {
|
2019-05-20 07:33:10 +00:00
|
|
|
type: PLATFORMS_MAP.mobile,
|
2017-12-20 21:29:06 +00:00
|
|
|
};
|
|
|
|
},
|
2017-06-08 22:12:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/* Windows Phone */
|
|
|
|
{
|
|
|
|
test(parser) {
|
|
|
|
return parser.getBrowserName() === 'windows phone';
|
|
|
|
},
|
|
|
|
describe() {
|
|
|
|
return {
|
2019-05-20 07:33:10 +00:00
|
|
|
type: PLATFORMS_MAP.mobile,
|
2017-12-20 21:29:06 +00:00
|
|
|
vendor: 'Microsoft',
|
|
|
|
};
|
|
|
|
},
|
2017-06-08 22:12:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/* Android Tablet */
|
|
|
|
{
|
|
|
|
test(parser) {
|
|
|
|
const osMajorVersion = Number(String(parser.getOSVersion()).split('.')[0]);
|
|
|
|
return parser.getOSName(true) === 'android' && (osMajorVersion >= 3);
|
|
|
|
},
|
|
|
|
describe() {
|
|
|
|
return {
|
2019-05-20 07:33:10 +00:00
|
|
|
type: PLATFORMS_MAP.tablet,
|
2017-12-20 21:29:06 +00:00
|
|
|
};
|
|
|
|
},
|
2017-06-08 22:12:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/* Android Mobile */
|
|
|
|
{
|
|
|
|
test(parser) {
|
|
|
|
return parser.getOSName(true) === 'android';
|
|
|
|
},
|
|
|
|
describe() {
|
|
|
|
return {
|
2019-05-20 07:33:10 +00:00
|
|
|
type: PLATFORMS_MAP.mobile,
|
2017-12-20 21:29:06 +00:00
|
|
|
};
|
|
|
|
},
|
2017-06-08 22:12:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/* desktop */
|
|
|
|
{
|
|
|
|
test(parser) {
|
|
|
|
return parser.getOSName(true) === 'macos';
|
|
|
|
},
|
|
|
|
describe() {
|
|
|
|
return {
|
2019-05-20 07:33:10 +00:00
|
|
|
type: PLATFORMS_MAP.desktop,
|
2017-12-20 21:29:06 +00:00
|
|
|
vendor: 'Apple',
|
2017-06-08 22:12:44 +00:00
|
|
|
};
|
2017-12-20 21:29:06 +00:00
|
|
|
},
|
2017-06-08 22:12:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/* Windows */
|
|
|
|
{
|
|
|
|
test(parser) {
|
|
|
|
return parser.getOSName(true) === 'windows';
|
|
|
|
},
|
|
|
|
describe() {
|
|
|
|
return {
|
2019-05-20 07:33:10 +00:00
|
|
|
type: PLATFORMS_MAP.desktop,
|
2017-12-20 21:29:06 +00:00
|
|
|
};
|
|
|
|
},
|
2017-06-08 22:12:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/* Linux */
|
|
|
|
{
|
|
|
|
test(parser) {
|
|
|
|
return parser.getOSName(true) === 'linux';
|
|
|
|
},
|
|
|
|
describe() {
|
|
|
|
return {
|
2019-05-20 07:33:10 +00:00
|
|
|
type: PLATFORMS_MAP.desktop,
|
2017-12-20 21:29:06 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
2019-02-06 08:47:28 +00:00
|
|
|
|
|
|
|
/* PlayStation 4 */
|
|
|
|
{
|
|
|
|
test(parser) {
|
|
|
|
return parser.getOSName(true) === 'playstation 4';
|
|
|
|
},
|
|
|
|
describe() {
|
|
|
|
return {
|
2019-05-20 07:33:10 +00:00
|
|
|
type: PLATFORMS_MAP.tv,
|
2019-02-06 08:47:28 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
2019-07-07 09:55:53 +00:00
|
|
|
|
|
|
|
/* Roku */
|
|
|
|
{
|
|
|
|
test(parser) {
|
|
|
|
return parser.getOSName(true) === 'roku';
|
|
|
|
},
|
|
|
|
describe() {
|
|
|
|
return {
|
|
|
|
type: PLATFORMS_MAP.tv,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
2017-06-08 22:12:44 +00:00
|
|
|
];
|