-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsiteguard.js
104 lines (93 loc) · 4.11 KB
/
siteguard.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*!-----------------------------------------------------------------------------
* SiteGuard - Version 1.1.2
* Author: Luiz Bizzio
* License: MIT
* Repository: https://github.com/luizbizzio/siteguard
* Published: 2024-11-08
* -------------------------------------------------------------------------- */
// Dev Tools Detector
function af() {
var e = !1; // Initializes a variable to track the detection of DevTools
setInterval(function() {
var t = performance.now(); // Gets the current time in milliseconds
console.profile(); // Starts a profiling session for performance analysis
console.profileEnd(); // Ends the profiling session
console.clear && console.clear(); // Clears the console if supported
// Detects if the developer tools are open
if (10 < performance.now() - t && !e) { // Adjusts the sensitivity of the performance detector (Recommended value between 5 and 10ms).
// Setting the threshold below 10ms may cause the script to trigger on older devices,
// Higher values increase sensitivity, potentially causing false positives.
e = true; // Set e to true to indicate DevTools are detected
document.documentElement.innerHTML = ""; // Clear the document
location.reload(); // Reload the page
}
}, 1); // Executes the function every millisecond
}
af(); // Invokes the function to start detection
// 1. Prevents users from dragging elements
document.addEventListener("dragstart", e => e.preventDefault()); // Prevents the default drag behavior
// 2. Blocks middle mouse button clicks
document.addEventListener("auxclick", e => {
if (1 === e.button) { // Checks if the middle mouse button was clicked
e.stopPropagation(); // Prevents the event from bubbling up
e.preventDefault(); // Prevents the default action
}
});
// 3. Disables the context menu (right-click)
document.addEventListener("contextmenu", function(e) {
e.preventDefault(); // Prevents the context menu from appearing
});
// 4. Blocks key combinations
document.onkeydown = e => {
// Defines an array of key combinations to block
[{
ctrl: !0,
shift: !0,
code: "KeyI" // Ctrl + Shift + I for Developer Tools
}, {
ctrl: !0,
shift: !0,
code: "KeyJ" // Ctrl + Shift + J for JavaScript console
}, {
ctrl: !0,
shift: !0,
code: "KeyV" // Ctrl + Shift + V for paste
}, {
ctrl: !0,
shift: !0,
code: "KeyC" // Ctrl + Shift + C for element inspector
}, {
ctrl: !0,
code: "KeyU" // Ctrl + U for view source
}, {
ctrl: !0,
code: "KeyP" // Ctrl + P for print
}, {
ctrl: !0,
code: "KeyS" // Ctrl + S for save
}, {
ctrl: !0,
code: "KeyJ" // Ctrl + J for downloads
}, {
ctrl: !0,
code: "KeyF" // Ctrl + F for find
}, {
code: "F12" // F12 for Developer Tools
}].some(t => !!t.ctrl === e.ctrlKey && !!t.shift === e.shiftKey && e.code === t.code) && e.preventDefault();
};
// 5. Prevents text selection on the entire body of the document
document.addEventListener("DOMContentLoaded", function() {
// Sets the user-select property to none to disable text selection
document.body.style.setProperty('user-select', 'none', 'important');
// Style to hide all content during printing
const printStyle = document.createElement("style");
printStyle.type = "text/css";
printStyle.media = "print";
printStyle.innerHTML = "* { display: none !important; }"; // Hides all content during print
document.head.appendChild(printStyle);
// Style to disable text selection for various browsers
const selectTextCss = document.createElement("style");
selectTextCss.type = "text/css";
selectTextCss.innerHTML = "body {-webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;}"; // Prevents text selection
document.head.appendChild(selectTextCss);
});