-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics.js
88 lines (79 loc) · 2.51 KB
/
metrics.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Dependencies:
// https://cdn.jsdelivr.net/npm/@fingerprintjs/fingerprintjs@3/dist/fp.min.js
const ConsoleSilentMode = true; // убрать комменты
function getMetrics() {
let detectApp = newDetectApp();
return (async () => {
return await Promise.all([getFPJSLibDataPromise(), detectApp.getUserApps(), isPrivateMode(), getOpenPorts(), getExtensions()]).then(values => {
let Metrics = {};
let fingerprintJS = values[0].components;
Object.keys(fingerprintJS).forEach(function (key) {
Metrics[key] = fingerprintJS[key].value === undefined ? null : fingerprintJS[key].value;
switch (key) {
case 'languages': {
let languages = [];
Metrics[key].forEach(function (langs) {
if (Array.isArray(langs)) {
langs.forEach(function (lang) {
languages.push(lang);
});
} else {
languages.push(langs);
}
});
Metrics[key] = languages;
}
}
});
Metrics['fingerprintJSHash'] = values[0].visitorId;
Metrics['apps'] = [];
values[1].forEach(function (status, appTitle) {
Metrics['apps'].push({app: appTitle, status: status})
})
Metrics['browserPrivateMode'] = values[2];
Metrics['browser'] = {
'opera': isOpera,
'firefox': isFirefox,
'safari': isSafari,
'ie': isIE,
'edge': isEdge || isEdgeChromium,
'chrome': isChrome || (!isOpera && !isFirefox &&
!isSafari && !isIE && !isEdge && !isEdgeChromium && !isBlink),
'blink': isBlink
};
Metrics['browserName'] = '';
Object.keys(Metrics['browser']).forEach(function (key) {
if (Metrics['browser'][key]) {
Metrics['browserName'] += [key] + ';';
}
});
Metrics['ports'] = values[3];
Metrics['extensions'] = values[4];
return Metrics;
})
})()
}
function getFPJSLibDataPromise() {
doConsoleLog('fingerprint js start');
const fpPromise = FingerprintJS.load()
return (async () => {
doConsoleLog('fingerprint js');
const fp = await fpPromise;
return await fp.get();
})()
}
function doConsoleLog(logMessage) {
if (ConsoleSilentMode) return;
console.log(logMessage);
}
// Debug
function consolePrintGetMetrics() {
getMetrics().then(value => {
console.log(value);
});
}
function consolePrintJSONGetMetrics() {
getMetrics().then(value => {
console.log(JSON.stringify(value));
});
}