UNPKG

@wprimadi/lockdown

Version:

LOCKDOWN (Log Obfuscation & Console Kill-switch with Devtools Override Warning Network) - Lightweight JavaScript library to secure your website by blocking DevTools access, disabling context menu, shortcuts, text copy/cut/select, and more. Built for front

1 lines 1.16 kB
const lockdown=function(){let e={redirectUrl:"",disableContextMenu:!0,disableShorcuts:!0,disableTextCopy:!0,disableTextCut:!0,disableTextSelection:!0,disableMouseDown:!0,disableDevTools:!0};function t(){e.disableDevTools&&setInterval((()=>{(window.outerWidth-window.innerWidth>160||window.outerHeight-window.innerHeight>160)&&(e.redirectUrl?window.location.href=e.redirectUrl:console.warn("DevTools opened!"))}),1e3)}function n(e,t){document.addEventListener(t,(function(e){e.preventDefault()}))}return{init:function(o={}){e={...e,...o},t(),e.disableContextMenu&&n(document,"contextmenu"),e.disableShorcuts&&window.addEventListener("keydown",(function(e){const t=e.key.toLowerCase();[e.metaKey&&e.altKey&&["i","j","c","u"].includes(t),e.metaKey&&e.shiftKey&&"c"===t,e.ctrlKey&&e.shiftKey&&["i","j","c"].includes(t),"F12"===e.key,e.ctrlKey&&"u"===t].some(Boolean)&&e.preventDefault()})),e.disableTextCopy&&n(document,"copy"),e.disableTextCut&&n(document,"cut"),e.disableTextSelection&&document.addEventListener("selectstart",(function(e){e.preventDefault()})),e.disableMouseDown&&document.addEventListener("mousedown",(function(e){e.preventDefault()}))}}}();