/** * Website Debugger Stopper * Prevents users from opening developer tools using various methods */ class DebuggerStopper { constructor() { this.isDebuggerActive = false; this.consoleWarningShown = false; this.init(); } init() { this.blockKeyboardShortcuts(); this.blockRightClick(); this.detectDevTools(); this.blockConsoleAccess(); this.preventTextSelection(); this.addAntiDebugLoop(); console.log('🛡️ Debugger protection activated'); } // Block common keyboard shortcuts for opening dev tools blockKeyboardShortcuts() { document.addEventListener('keydown', (e) => { // F12 - Developer Tools if (e.key === 'F12') { e.preventDefault(); e.stopPropagation(); this.showWarning('Developer tools are disabled on this website.'); return false; } // Ctrl+Shift+I - Developer Tools if (e.ctrlKey && e.shiftKey && e.key === 'I') { e.preventDefault(); e.stopPropagation(); this.showWarning('Developer tools are disabled on this website.'); return false; } // Ctrl+Shift+J - Console if (e.ctrlKey && e.shiftKey && e.key === 'J') { e.preventDefault(); e.stopPropagation(); this.showWarning('Console access is disabled on this website.'); return false; } // Ctrl+Shift+C - Element Inspector if (e.ctrlKey && e.shiftKey && e.key === 'C') { e.preventDefault(); e.stopPropagation(); this.showWarning('Element inspector is disabled on this website.'); return false; } // Ctrl+U - View Source if (e.ctrlKey && e.key === 'u') { e.preventDefault(); e.stopPropagation(); this.showWarning('View source is disabled on this website.'); return false; } // Ctrl+S - Save Page if (e.ctrlKey && e.key === 's') { e.preventDefault(); e.stopPropagation(); this.showWarning('Saving page is disabled on this website.'); return false; } // Ctrl+A - Select All (optional, can be removed if too restrictive) if (e.ctrlKey && e.key === 'a') { e.preventDefault(); e.stopPropagation(); this.showWarning('Select all is disabled on this website.'); return false; } // Ctrl+P - Print if (e.ctrlKey && e.key === 'p') { e.preventDefault(); e.stopPropagation(); this.showWarning('Printing is disabled on this website.'); return false; } // F5 and Ctrl+R - Refresh (optional) if (e.key === 'F5' || (e.ctrlKey && e.key === 'r')) { // Allow refresh but clear any debug attempts this.clearConsole(); } }); // Block keyup events as well for extra security document.addEventListener('keyup', (e) => { if (e.key === 'F12' || (e.ctrlKey && e.shiftKey && ['I', 'J', 'C'].includes(e.key)) || (e.ctrlKey && ['u', 's', 'a', 'p'].includes(e.key))) { e.preventDefault(); e.stopPropagation(); return false; } }); } // Block right-click context menu blockRightClick() { document.addEventListener('contextmenu', (e) => { e.preventDefault(); e.stopPropagation(); this.showWarning('Right-click is disabled on this website.'); return false; }); // Also block on window window.addEventListener('contextmenu', (e) => { e.preventDefault(); return false; }); } // Detect if developer tools are open detectDevTools() { let devtools = { open: false, orientation: null }; const threshold = 160; setInterval(() => { if (window.outerHeight - window.innerHeight > threshold || window.outerWidth - window.innerWidth > threshold) { if (!devtools.open) { devtools.open = true; this.handleDevToolsOpen(); } } else { devtools.open = false; } }, 500); // Alternative detection method using console let element = new Image(); Object.defineProperty(element, 'id', { get: () => { this.handleDevToolsOpen(); return 'devtools-detector'; } }); setInterval(() => { console.log('%c', element); }, 1000); } // Handle when dev tools are detected as open handleDevToolsOpen() { if (!this.isDebuggerActive) { this.isDebuggerActive = true; this.showWarning('Developer tools detected! Please close them to continue.'); // Optional: Redirect or take other action // window.location.href = '/'; // Clear the page content // document.body.innerHTML = '

Developer tools are not allowed on this website.

'; } } // Block console access and clear it blockConsoleAccess() { // Override console methods const originalLog = console.log; const originalWarn = console.warn; const originalError = console.error; const originalInfo = console.info; const originalDebug = console.debug; console.log = () => {}; console.warn = () => {}; console.error = () => {}; console.info = () => {}; console.debug = () => {}; console.clear = () => {}; console.table = () => {}; console.group = () => {}; console.groupEnd = () => {}; console.time = () => {}; console.timeEnd = () => {}; // Show warning message in console if (!this.consoleWarningShown) { originalWarn('🛡️ Console access is restricted on this website for security reasons.'); this.consoleWarningShown = true; } // Clear console periodically setInterval(() => { this.clearConsole(); }, 2000); } // Clear console clearConsole() { try { console.clear(); } catch (e) { // Ignore errors } } // Prevent text selection preventTextSelection() { document.addEventListener('selectstart', (e) => { e.preventDefault(); return false; }); document.addEventListener('dragstart', (e) => { e.preventDefault(); return false; }); // CSS-based text selection prevention const style = document.createElement('style'); style.textContent = ` * { -webkit-user-select: none !important; -moz-user-select: none !important; -ms-user-select: none !important; user-select: none !important; -webkit-touch-callout: none !important; -webkit-tap-highlight-color: transparent !important; } input, textarea { -webkit-user-select: text !important; -moz-user-select: text !important; -ms-user-select: text !important; user-select: text !important; } `; document.head.appendChild(style); } // Add anti-debug loop addAntiDebugLoop() { setInterval(() => { debugger; }, 100); // Alternative anti-debug method (function() { let start = Date.now(); debugger; if (Date.now() - start > 100) { this.handleDevToolsOpen(); } }).bind(this)(); } // Show warning message showWarning(message) { // Remove existing warnings const existingWarning = document.getElementById('debugger-warning'); if (existingWarning) { existingWarning.remove(); } // Create warning notification const warning = document.createElement('div'); warning.id = 'debugger-warning'; warning.style.cssText = ` position: fixed; top: 20px; right: 20px; background: linear-gradient(135deg, #ff4757 0%, #ff3742 100%); color: white; padding: 20px 25px; border-radius: 12px; box-shadow: 0 10px 30px rgba(255,71,87,0.4); z-index: 999999; font-weight: 600; animation: slideInFromRight 0.5s ease; max-width: 400px; border: 1px solid rgba(255,255,255,0.2); font-family: Arial, sans-serif; font-size: 14px; line-height: 1.4; `; warning.innerHTML = `
Security Notice
${message}
`; // Add CSS animation if not already added if (!document.getElementById('debugger-warning-styles')) { const style = document.createElement('style'); style.id = 'debugger-warning-styles'; style.textContent = ` @keyframes slideInFromRight { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } } `; document.head.appendChild(style); } document.body.appendChild(warning); // Auto-remove after 5 seconds setTimeout(() => { if (warning.parentNode) { warning.style.animation = 'slideInFromRight 0.3s ease reverse'; setTimeout(() => { if (warning.parentNode) { warning.remove(); } }, 300); } }, 5000); } // Disable the debugger stopper (for admin use) disable() { console.log('🔓 Debugger protection disabled'); // This method can be called to disable protection if needed // Implementation would remove event listeners and restore console } } // Initialize debugger stopper when DOM is loaded document.addEventListener('DOMContentLoaded', () => { window.debuggerStopper = new DebuggerStopper(); }); // Also initialize immediately if DOM is already loaded if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => { window.debuggerStopper = new DebuggerStopper(); }); } else { window.debuggerStopper = new DebuggerStopper(); } // Prevent script tampering Object.freeze(DebuggerStopper); Object.freeze(DebuggerStopper.prototype);