-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
82 lines (74 loc) · 2.24 KB
/
index.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
/* global CustomEvent */
/*
* cracker-trap based on devtools-detect
* Detect if web developer tools is open to hardening apps
* https://github.com/bioverflow/cracker-trap
* by Reverse Bytes
* GPL 3.0
*/
((function () {
var devtools = {
open: false,
orientation: null,
undocked: null
}
var threshold = 160
// Emit an event when devtools status is changed
var emitEvent = function emitEvent (state, orientation, undocked) {
try {
window.dispatchEvent(new CustomEvent('onDevToolsChange', {
detail: {
open: state,
orientation: orientation,
undocked: undocked
}
}))
} catch (e) {
var event = document.createEvent('CustomEvent')
var data = {
'open': state,
'orientation': orientation,
'undocked': undocked
}
event.initCustomEvent('onDevToolsChange', true, false, data)
document.documentElement.dispatchEvent(event)
}
}
function timeValidation () {
var startTime = new Date()
debugger // eslint-disable-line
var endTime = new Date()
return endTime - startTime > 100
}
// Every half second check if developer tools is opened or not
setInterval(function () {
// Check between browser width/height and visible width/height and compare
// with max threshold.
var widthThreshold = window.outerWidth - window.innerWidth > threshold
var heightThreshold = window.outerHeight - window.innerHeight > threshold
var orientation = widthThreshold ? 'vertical' : 'horizontal'
if (heightThreshold === true || widthThreshold === true) {
if (devtools.open === true || devtools.orientation !== orientation) {
emitEvent(true, orientation, null)
}
devtools.open = true
devtools.orientation = orientation
devtools.undocked = false
} else if (timeValidation() === true) {
emitEvent(true, null, true)
devtools.undocked = true
} else {
if (devtools.open) {
emitEvent(false, null, null)
}
devtools.open = false
devtools.orientation = null
devtools.undocked = null
}
}, 500)
if (typeof module !== 'undefined' && module.exports) {
module.exports = devtools
} else {
window.devtools = devtools
}
})())