-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbehavior.js
More file actions
58 lines (50 loc) · 1.5 KB
/
Copy pathbehavior.js
File metadata and controls
58 lines (50 loc) · 1.5 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// behavior.js - simple typing & mouse behavior profiler
(function () {
const origin = location.origin;
let lastKeyTime = null;
let keyIntervals = [];
let mouseMoves = 0;
let lastMouseTime = null;
function sendBehaviorLog(eventType, data) {
chrome.runtime.sendMessage({
type: "log",
level: "info",
message: `Behavior event: ${eventType}`,
details: { origin, ...data }
});
}
// Keyboard timing profiling
document.addEventListener("keydown", () => {
const now = performance.now();
if (lastKeyTime !== null) {
const diff = now - lastKeyTime;
keyIntervals.push(diff);
if (keyIntervals.length > 50) keyIntervals.shift();
const avg =
keyIntervals.reduce((a, b) => a + b, 0) / (keyIntervals.length || 1);
if (avg < 40 || avg > 700) {
sendBehaviorLog("typing-anomaly", {
avgKeyIntervalMs: Math.round(avg),
keyCount: keyIntervals.length
});
}
}
lastKeyTime = now;
});
// Mouse movement profiling
document.addEventListener("mousemove", () => {
const now = performance.now();
mouseMoves++;
if (!lastMouseTime) lastMouseTime = now;
if (now - lastMouseTime > 5000) {
if (mouseMoves > 500) {
sendBehaviorLog("mouse-anomaly", {
moves: mouseMoves,
intervalMs: Math.round(now - lastMouseTime)
});
}
mouseMoves = 0;
lastMouseTime = now;
}
});
})();