Created
August 4, 2023 21:29
-
-
Save librz/1f8bde6f1803abd688c1451e91f8b430 to your computer and use it in GitHub Desktop.
Evil hack that prevents user from inspecting web page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function check() { | |
const minimalUserResponseInMiliseconds = 200; | |
console.clear(); | |
let before = new Date().getTime(); | |
debugger; | |
let after = new Date().getTime(); | |
if (after - before > minimalUserResponseInMiliseconds) { | |
document.write(" Don't open Developer Tools."); | |
window.location.reload(); | |
} | |
setTimeout(check, 100); | |
} | |
check(); | |
window.onload = function () { | |
// prevent right click to open context menu | |
document.addEventListener( | |
"contextmenu", | |
function (e) { | |
e.preventDefault(); | |
}, | |
false | |
); | |
// prevent dev related keyboard shortcuts | |
document.addEventListener( | |
"keydown", | |
function (e) { | |
function disableEvent() { | |
e.stopPropagation(); | |
e.preventDefault(); | |
} | |
/* shortcuts for open dev tools */ | |
// both windows & mac: F12 | |
if (e.keyCode == 123) { | |
disableEvent(); | |
return; | |
} | |
// windows: ctrl + shift + i | |
if (e.ctrlKey && e.shiftKey && e.keyCode == 73) { | |
disableEvent(); | |
return; | |
} | |
// windows: ctrl + shift + j | |
if (e.ctrlKey && e.shiftKey && e.keyCode == 74) { | |
disableEvent(); | |
return; | |
} | |
/* shortcuts for open/save source code */ | |
// view source on windows: ctrl + u | |
if (e.ctrlKey && e.keyCode == 85) { | |
disableEvent(); | |
return; | |
} | |
// save page as. mac: cmd + s; windows: ctrl + s; | |
if ( | |
e.keyCode == 83 && | |
(navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey) | |
) { | |
disableEvent(); | |
return; | |
} | |
}, | |
false | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment