Last active
February 5, 2024 02:54
-
-
Save ArthurKun21/00cba91929681537e37641172cc0dd5e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// ==UserScript== | |
// @name Always On Focus | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Prevent websites from detecting when you switch tabs or unfocus the window | |
// @author You | |
// @match *://*/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
// Store the initial state of document.hasFocus | |
const originalHasFocus = document.hasFocus; | |
// Override document.hasFocus based on window focus | |
window.addEventListener('focus', function() { | |
document.hasFocus = function() { return true; }; | |
}); | |
window.addEventListener('blur', function() { | |
document.hasFocus = function() { return false; }; | |
}); | |
// Restore the original behavior after the script runs | |
setTimeout(function() { | |
document.hasFocus = originalHasFocus; | |
}, 0); | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment