1
0
mirror of https://github.com/lancedikson/bowser synced 2024-10-27 20:34:22 +00:00
lancedikson_bowser/src/parser-platforms.js

267 lines
4.5 KiB
JavaScript
Raw Normal View History

import Utils from './utils.js';
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 [
/* Googlebot */
{
test: [/googlebot/i],
describe() {
return {
type: 'bot',
vendor: 'Google',
};
},
},
/* Huawei */
{
test: [/huawei/i],
describe(ua) {
const model = Utils.getFirstMatch(/(can-l01)/i, ua) && 'Nova';
const platform = {
type: PLATFORMS_MAP.mobile,
2018-12-30 08:18:58 +00:00
vendor: 'Huawei',
};
if (model) {
2018-12-30 08:18:58 +00:00
platform.model = model;
}
return platform;
},
},
2017-06-08 22:12:44 +00:00
/* Nexus Tablet */
{
test: [/nexus\s*(?:7|8|9|10).*/i],
2017-06-08 22:12:44 +00:00
describe() {
return {
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 {
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 */
{
test: [/Macintosh(.*?) FxiOS(.*?) Version\//],
describe() {
return {
type: PLATFORMS_MAP.tablet,
vendor: 'Apple',
model: 'iPad',
};
},
},
/* Amazon Kindle Fire */
{
test: [/kftt build/i],
describe() {
return {
type: PLATFORMS_MAP.tablet,
vendor: 'Amazon',
2017-12-20 21:29:06 +00:00
model: 'Kindle Fire HD 7',
};
},
},
/* Another Amazon Tablet with Silk */
2017-06-08 22:12:44 +00:00
{
test: [/silk/i],
describe() {
return {
type: PLATFORMS_MAP.tablet,
2017-12-20 21:29:06 +00:00
vendor: 'Amazon',
};
},
2017-06-08 22:12:44 +00:00
},
/* Tablet */
{
test: [/tablet(?! pc)/i],
2017-06-08 22:12:44 +00:00
describe() {
return {
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) {
const model = Utils.getFirstMatch(/(ipod|iphone)/i, ua);
2017-06-08 22:12:44 +00:00
return {
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 */
{
test: [/nexus\s*[0-6].*/i, /galaxy nexus/i],
2017-06-08 22:12:44 +00:00
describe() {
return {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
type: PLATFORMS_MAP.tv,
2019-02-06 08:47:28 +00:00
};
},
},
/* Roku */
{
test(parser) {
return parser.getOSName(true) === 'roku';
},
describe() {
return {
type: PLATFORMS_MAP.tv,
};
},
},
2017-06-08 22:12:44 +00:00
];