forked from WhichBrowser/Parser-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBot.js
More file actions
37 lines (34 loc) · 1.1 KB
/
Bot.js
File metadata and controls
37 lines (34 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* eslint-disable require-jsdoc */
const Constants = require('../../../constants');
const Applications = require('../../../data/Applications');
class Bot {
static detectBot(ua) {
/* Detect bots based on url in the UA string */
if (/\+https?:\/\//iu.test(ua)) {
this.data.browser.reset();
this.data.os.reset();
this.data.engine.reset();
this.data.device.reset();
this.data.device.type = Constants.deviceType.BOT;
}
/* Detect bots based on common markers */
if (/(?:Bot|Robot|Spider|Crawler)([/);]|$)/iu.test(ua) && !/CUBOT/iu.test(ua)) {
this.data.browser.reset();
this.data.os.reset();
this.data.engine.reset();
this.data.device.reset();
this.data.device.type = Constants.deviceType.BOT;
}
/* Detect based on a predefined list or markers */
const bot = Applications.identifyBot(ua);
if (bot) {
this.data.browser = bot;
this.data.os.reset();
this.data.engine.reset();
this.data.device.reset();
this.data.device.type = Constants.deviceType.BOT;
}
return this;
}
}
module.exports = Bot;