Advanced anti-detection with fullscreen control + undetectable anti-AFK
// ==UserScript==
// @name No Detect Switch Tab
// @namespace http://tampermonkey.net/
// @version 3.0
// @description Advanced anti-detection with fullscreen control + undetectable anti-AFK
// @author Zabuzz
// @match *://*/*
// @run-at document-start
// @grant none
// ==/UserScript==
(function() {
'use strict';
// ===== IMPROVED VISIBILITY BLOCKING =====
const setupVisibilityProtection = () => {
try {
// Simpan original values dulu
const originalProperties = {};
const targetProperties = {
'hidden': false,
'visibilityState': 'visible',
'webkitHidden': false,
'webkitVisibilityState': 'visible',
'mozHidden': false,
'mozVisibilityState': 'visible',
'msHidden': false,
'msVisibilityState': 'visible'
};
Object.keys(targetProperties).forEach(prop => {
if (prop in document) {
try {
originalProperties[prop] = Object.getOwnPropertyDescriptor(document, prop);
Object.defineProperty(document, prop, {
get: () => targetProperties[prop],
configurable: true
});
} catch (e) {}
}
});
} catch (e) {}
};
// ===== IMPROVED FULLSCREEN CONTROL =====
const setupFullscreenControl = () => {
let userFullscreenState = false;
let websiteFullscreenState = false;
// Simpan original methods
const originals = {
requestFullscreen: Element.prototype.requestFullscreen ||
Element.prototype.webkitRequestFullscreen ||
Element.prototype.mozRequestFullscreen ||
Element.prototype.msRequestFullscreen,
exitFullscreen: document.exitFullscreen ||
document.webkitExitFullscreen ||
document.mozExitFullscreen ||
document.msExitFullscreen
};
// Override requestFullscreen - lebih permisif
if (originals.requestFullscreen) {
Element.prototype.requestFullscreen = function(...args) {
console.log('ADVANCED: Website fullscreen request - ALLOWED WITH CONTROL');
websiteFullscreenState = true;
return originals.requestFullscreen.call(this, ...args).then(() => {
// Apply proper fullscreen styling
setTimeout(() => {
document.documentElement.style.width = '100vw';
document.documentElement.style.height = '100vh';
document.body.style.width = '100vw';
document.body.style.height = '100vh';
}, 100);
return this;
}).catch(err => {
console.log('ADVANCED: Fullscreen failed:', err);
});
};
}
// Override exitFullscreen - lebih smart
if (originals.exitFullscreen) {
document.exitFullscreen = function(...args) {
// Allow website to exit fullscreen jika user juga mau exit
if (!userFullscreenState || websiteFullscreenState) {
websiteFullscreenState = false;
return originals.exitFullscreen.call(this, ...args).then(() => {
// Reset styling
document.documentElement.style.width = '';
document.documentElement.style.height = '';
document.body.style.width = '';
document.body.style.height = '';
});
}
console.log('ADVANCED: Blocked unwanted fullscreen exit');
return Promise.resolve();
};
}
// User fullscreen control
const userToggleFullscreen = () => {
const element = document.documentElement;
if (!userFullscreenState) {
// Enter fullscreen
const requestMethod = element.requestFullscreen ||
element.webkitRequestFullscreen ||
element.mozRequestFullscreen ||
element.msRequestFullscreen;
if (requestMethod) {
requestMethod.call(element).then(() => {
userFullscreenState = true;
console.log('ADVANCED: User fullscreen activated');
// Force proper dimensions
document.documentElement.style.width = '100vw';
document.documentElement.style.height = '100vh';
document.body.style.width = '100vw';
document.body.style.height = '100vh';
}).catch(err => {
console.log('ADVANCED: User fullscreen failed:', err);
});
}
} else {
// Exit fullscreen
originals.exitFullscreen.call(document).then(() => {
userFullscreenState = false;
console.log('ADVANCED: User fullscreen exited');
// Reset styling
document.documentElement.style.width = '';
document.documentElement.style.height = '';
document.body.style.width = '';
document.body.style.height = '';
});
}
};
// Emergency exit - lebih reliable
const emergencyExitFullscreen = () => {
userFullscreenState = false;
websiteFullscreenState = false;
// Try all exit methods
const exitMethods = [
() => document.exitFullscreen?.(),
() => document.webkitExitFullscreen?.(),
() => document.mozCancelFullScreen?.(),
() => document.msExitFullscreen?.()
];
exitMethods.forEach(method => {
try { method().catch(() => {}); } catch(e) {}
});
// Multiple ESC events
for (let i = 0; i < 2; i++) {
setTimeout(() => {
const escEvent = new KeyboardEvent('keydown', {
key: 'Escape', code: 'Escape', keyCode: 27, which: 27
});
document.dispatchEvent(escEvent);
}, i * 50);
}
// Force styling reset
document.documentElement.style.width = '';
document.documentElement.style.height = '';
document.body.style.width = '';
document.body.style.height = '';
console.log('ADVANCED: Emergency exit executed');
};
return { userToggleFullscreen, emergencyExitFullscreen };
};
// ===== MINIMAL EVENT BLOCKING =====
const setupEventBlocking = () => {
// HANYA block event yang benar-benar mengganggu, biarkan tab switching
const carefullyBlockedEvents = ['beforeunload'];
carefullyBlockedEvents.forEach(eventType => {
const handler = (e) => {
// Hanya prevent default untuk beforeunload
if (eventType === 'beforeunload' && e.type === 'beforeunload') {
e.preventDefault();
e.returnValue = '';
}
e.stopImmediatePropagation();
};
window.addEventListener(eventType, handler, { capture: true });
document.addEventListener(eventType, handler, { capture: true });
});
// Biarkan visibilitychange dan blur events agar tab switching berfungsi
// Tapi kita override state-nya di setupVisibilityProtection
};
// ===== IMPROVED KEYBOARD CONTROL =====
const setupKeyboardControl = () => {
const { userToggleFullscreen, emergencyExitFullscreen } = setupFullscreenControl();
let lastKeyTime = 0;
document.addEventListener('keydown', (e) => {
const now = Date.now();
// Prevent rapid fire
if (now - lastKeyTime < 500) return;
// Ctrl+Shift+F - User fullscreen toggle
if (e.ctrlKey && e.shiftKey && e.key === 'F') {
if (e.repeat) return;
e.preventDefault();
e.stopImmediatePropagation();
lastKeyTime = now;
userToggleFullscreen();
return;
}
// Ctrl+Shift+E - Emergency exit
if (e.ctrlKey && e.shiftKey && e.key === 'E') {
if (e.repeat) return;
e.preventDefault();
e.stopImmediatePropagation();
lastKeyTime = now;
emergencyExitFullscreen();
return;
}
// Jangan block F11 sepenuhnya, tapi beri warning
if (e.key === 'F11' && !e.ctrlKey && !e.shiftKey) {
console.log('ADVANCED: F11 detected - use Ctrl+Shift+F for better control');
// Biarkan F11 bekerja normal
return;
}
}, { capture: true, passive: false });
};
// ===== IMPROVED DETECTION PREVENTION =====
const setupDetectionPrevention = () => {
// Override focus methods secara subtle
const originalHasFocus = document.hasFocus;
document.hasFocus = function() {
try {
return originalHasFocus.call(this);
} catch (e) {
return true;
}
};
// Biarkan active element normal
// Override fullscreen detection properties
const fullscreenProps = [
'fullscreenElement', 'webkitFullscreenElement',
'mozFullScreenElement', 'msFullscreenElement'
];
fullscreenProps.forEach(prop => {
if (prop in document) {
try {
Object.defineProperty(document, prop, {
get: function() {
// Return null untuk sembunyikan fullscreen state
return null;
},
configurable: true
});
} catch (e) {}
}
});
};
// ===== IMPROVED AUDIO PROTECTION =====
const setupAudioProtection = () => {
// Prevent auto-pause ketika tab tidak aktif
const originalPause = HTMLMediaElement.prototype.pause;
HTMLMediaElement.prototype.pause = function() {
// Cek context - hanya block auto-pause, biarkan user-initiated pause
const stack = new Error().stack;
if (stack && (stack.includes('visibilitychange') || stack.includes('blur'))) {
console.log('ADVANCED: Blocked auto-pause attempt');
// Lower volume instead of pausing
this.volume = Math.max(0.1, this.volume - 0.2);
return;
}
return originalPause.call(this);
};
// Auto-resume media yang dipause oleh system
const resumeMedia = () => {
document.querySelectorAll('video, audio').forEach(media => {
if (media.paused && !media.ended && media.readyState > 2) {
media.play().catch(err => {
// Try muted playback as fallback
if (!media.muted) {
media.muted = true;
media.play().catch(() => {});
}
});
}
});
};
setInterval(resumeMedia, 3000);
};
// ===== TAB SWITCHING PROTECTION =====
const setupTabSwitchingProtection = () => {
// Biarkan tab switching normal, tapi maintain state
let isTabActive = true;
window.addEventListener('blur', () => {
isTabActive = false;
console.log('ADVANCED: Tab blurred - maintaining media playback');
}, { passive: true });
window.addEventListener('focus', () => {
isTabActive = true;
console.log('ADVANCED: Tab focused');
// Resume any media that might have been paused
setTimeout(() => {
document.querySelectorAll('video, audio').forEach(media => {
if (media.paused && !media.ended) {
media.play().catch(() => {});
}
});
}, 100);
}, { passive: true });
// Periodic state maintenance
setInterval(() => {
if (!isTabActive) {
// Simulate minimal activity ketika tab tidak aktif
window.dispatchEvent(new Event('focus'));
}
}, 5000);
};
// ===== FULLSCREEN STYLING =====
const setupFullscreenStyling = () => {
// Inject CSS untuk proper fullscreen appearance
const style = document.createElement('style');
style.id = 'advanced-fullscreen-styles';
style.textContent = `
:fullscreen, ::backdrop {
background-color: black !important;
}
:-webkit-full-screen, :-webkit-full-screen-ancestor {
background: black !important;
width: 100vw !important;
height: 100vh !important;
}
:-moz-full-screen, :-moz-full-screen-ancestor {
background: black !important;
}
`;
if (!document.getElementById('advanced-fullscreen-styles')) {
document.head.appendChild(style);
}
};
// ===== ULTIMATE ANTI-AFK SYSTEM =====
const setupAntiAFK = () => {
console.log('🕶️ ANTI-AFK SYSTEM: Initializing...');
let afkEnabled = true;
let lastActivity = Date.now();
let activityCounter = 0;
// ===== HUMAN-LIKE ACTIVITY SIMULATOR =====
class ActivitySimulator {
constructor() {
this.minDelay = 15000; // 15 detik minimum
this.maxDelay = 90000; // 90 detik maksimum
this.activityTypes = ['mouse', 'scroll', 'focus', 'key', 'click'];
}
// Random delay like human
getRandomDelay() {
return this.minDelay + Math.random() * (this.maxDelay - this.minDelay);
}
// Micro mouse movement (1-5 pixels) - undetectable
simulateMouseMove() {
if (!afkEnabled) return;
try {
const event = new MouseEvent('mousemove', {
view: window,
bubbles: true,
cancelable: true,
clientX: window.innerWidth / 2 + (Math.random() * 10 - 5),
clientY: window.innerHeight / 2 + (Math.random() * 10 - 5),
movementX: Math.random() * 4 - 2,
movementY: Math.random() * 4 - 2
});
// Dispatch to multiple targets randomly
const targets = [document, document.documentElement, document.body];
const target = targets[Math.floor(Math.random() * targets.length)];
target.dispatchEvent(event);
lastActivity = Date.now();
} catch (e) {}
}
// Micro scroll (1-3 pixels)
simulateScroll() {
if (!afkEnabled) return;
try {
const direction = Math.random() > 0.5 ? 1 : -1;
const event = new WheelEvent('wheel', {
deltaY: direction * (1 + Math.random() * 2),
bubbles: true,
cancelable: true
});
window.dispatchEvent(event);
lastActivity = Date.now();
} catch (e) {}
}
// Focus change simulation
simulateFocus() {
if (!afkEnabled) return;
try {
// Blur then focus
const blurEvent = new FocusEvent('blur', { bubbles: true });
const focusEvent = new FocusEvent('focus', { bubbles: true });
document.dispatchEvent(blurEvent);
setTimeout(() => {
document.dispatchEvent(focusEvent);
}, 50 + Math.random() * 100);
lastActivity = Date.now();
} catch (e) {}
}
// Safe key press (modifier keys only)
simulateKeyPress() {
if (!afkEnabled) return;
try {
const keys = ['Shift', 'Control', 'Alt', 'Meta', 'CapsLock'];
const key = keys[Math.floor(Math.random() * keys.length)];
const downEvent = new KeyboardEvent('keydown', {
key: key,
code: `Key${key.charAt(0).toUpperCase()}`,
bubbles: true,
cancelable: true
});
const upEvent = new KeyboardEvent('keyup', {
key: key,
code: `Key${key.charAt(0).toUpperCase()}`,
bubbles: true,
cancelable: true
});
document.dispatchEvent(downEvent);
setTimeout(() => document.dispatchEvent(upEvent), 30 + Math.random() * 70);
lastActivity = Date.now();
} catch (e) {}
}
// Occasional click simulation (rare)
simulateClick() {
if (!afkEnabled || Math.random() > 0.2) return; // 20% chance
try {
const event = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
document.body.dispatchEvent(event);
lastActivity = Date.now();
} catch (e) {}
}
// Get random activity
getRandomActivity() {
const activity = this.activityTypes[Math.floor(Math.random() * this.activityTypes.length)];
switch(activity) {
case 'mouse': return this.simulateMouseMove.bind(this);
case 'scroll': return this.simulateScroll.bind(this);
case 'focus': return this.simulateFocus.bind(this);
case 'key': return this.simulateKeyPress.bind(this);
case 'click': return this.simulateClick.bind(this);
default: return this.simulateMouseMove.bind(this);
}
}
// Schedule next activity
scheduleNextActivity() {
if (!afkEnabled) return;
const delay = this.getRandomDelay();
const activity = this.getRandomActivity();
setTimeout(() => {
if (afkEnabled) {
activity();
activityCounter++;
// Log occasionally
if (activityCounter % 10 === 0) {
console.log(`🕶️ ANTI-AFK: Activity #${activityCounter} - ${Date.now() - lastActivity}ms ago`);
}
// Schedule next
this.scheduleNextActivity();
}
}, delay);
}
start() {
// Start after random initial delay
setTimeout(() => {
this.scheduleNextActivity();
}, 5000 + Math.random() * 15000);
}
}
// ===== REAL ACTIVITY TRACKING =====
const trackRealActivity = () => {
const events = [
'mousedown', 'mousemove', 'mouseup',
'keydown', 'keyup', 'keypress',
'click', 'dblclick', 'contextmenu',
'wheel', 'scroll',
'touchstart', 'touchend', 'touchmove',
'focus', 'blur'
];
events.forEach(eventType => {
document.addEventListener(eventType, () => {
lastActivity = Date.now();
}, { passive: true });
window.addEventListener(eventType, () => {
lastActivity = Date.now();
}, { passive: true });
});
};
// ===== ANTI-DETECTION COUNTERMEASURES =====
const setupAntiDetection = () => {
// Intercept idle detection attempts
if ('requestIdleCallback' in window) {
const originalRequestIdleCallback = window.requestIdleCallback;
window.requestIdleCallback = function(callback, options) {
// Always return "not idle"
setTimeout(() => {
callback({
didTimeout: false,
timeRemaining: () => 50 + Math.random() * 50
});
}, 10);
return 0;
};
}
// Monitor for AFK warnings
const originalWarn = console.warn;
const originalError = console.error;
console.warn = function(...args) {
const msg = args.join(' ').toLowerCase();
if (msg.includes('idle') || msg.includes('afk') || msg.includes('inactive')) {
console.log('⚠️ AFK Warning detected - triggering activity');
simulator.simulateMouseMove();
simulator.simulateKeyPress();
}
return originalWarn.apply(this, args);
};
console.error = function(...args) {
const msg = args.join(' ').toLowerCase();
if (msg.includes('idle') || msg.includes('afk') || msg.includes('inactive')) {
console.log('🚨 AFK Error detected - maximum activity');
for (let i = 0; i < 5; i++) {
setTimeout(() => {
simulator.simulateMouseMove();
simulator.simulateScroll();
}, i * 100);
}
}
return originalError.apply(this, args);
};
};
// ===== INITIALIZE ANTI-AFK =====
const simulator = new ActivitySimulator();
trackRealActivity();
setupAntiDetection();
simulator.start();
// Monitor and log status
setInterval(() => {
const inactiveTime = Date.now() - lastActivity;
if (inactiveTime > 120000) { // 2 minutes
console.log(`🕶️ ANTI-AFK: ${Math.floor(inactiveTime/1000)}s inactive - simulating activity`);
simulator.simulateMouseMove();
}
}, 60000); // Check every minute
// Emergency manual trigger
window.triggerAntiAFK = () => {
console.log('🔄 Manual AFK trigger');
simulator.simulateMouseMove();
simulator.simulateScroll();
simulator.simulateKeyPress();
};
// Toggle function
window.toggleAntiAFK = () => {
afkEnabled = !afkEnabled;
console.log(`🕶️ ANTI-AFK: ${afkEnabled ? 'ENABLED' : 'DISABLED'}`);
return afkEnabled;
};
console.log('🕶️ ANTI-AFK SYSTEM: Ready - will simulate human activity');
return { triggerAntiAFK: window.triggerAntiAFK, toggleAntiAFK: window.toggleAntiAFK };
};
// ===== IMPROVED INITIALIZATION =====
const init = () => {
console.log('🎮 ADVANCED ANTI-DETECTION + ANTI-AFK ACTIVATED');
console.log('📋 Controls:');
console.log(' Ctrl+Shift+F - Toggle fullscreen');
console.log(' Ctrl+Shift+E - Emergency exit fullscreen');
console.log(' triggerAntiAFK() - Manual activity trigger');
console.log(' toggleAntiAFK() - Toggle anti-AFK on/off');
try {
setupVisibilityProtection();
setupEventBlocking();
setupKeyboardControl();
setupDetectionPrevention();
setupAudioProtection();
setupTabSwitchingProtection();
setupFullscreenStyling();
setupAntiAFK(); // NEW ANTI-AFK SYSTEM
} catch (error) {
console.log('ADVANCED: Some features failed:', error);
}
// Refresh protection periodically
setInterval(() => {
try {
setupVisibilityProtection();
setupFullscreenStyling();
} catch (e) {}
}, 15000);
};
// Delayed initialization untuk hindari konflik
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => {
setTimeout(init, 500);
});
} else {
setTimeout(init, 500);
}
})();