Skip to content

Instantly share code, notes, and snippets.

@thienha1
Last active March 11, 2021 04:31
Show Gist options
  • Save thienha1/f020e5d608f8f31480a368ed34794216 to your computer and use it in GitHub Desktop.
Save thienha1/f020e5d608f8f31480a368ed34794216 to your computer and use it in GitHub Desktop.
Focus Page.user.js
// ==UserScript==
// @name Focus
// @include *
// @run-at document-start
// @grant unsafeWindow
// ==/UserScript==
unsafeWindow.document.hasFocus = function () {return true;};
// visibilitychange events are captured and stopped
document.addEventListener("visibilitychange", function(e) {
e.stopImmediatePropagation();
}, true, true);
// document.visibilityState always returns false
Object.defineProperty(Document.prototype.wrappedJSObject, "hidden", {
get: exportFunction(function hidden() { return false; }, window.wrappedJSObject),
enumerable: true, configurable: true
});
// document.visibilityState always returns "visible"
Object.defineProperty(Document.prototype.wrappedJSObject, "visibilityState", {
get: exportFunction(function visibilityState() { return "visible"; }, window.wrappedJSObject),
enumerable: true, configurable: true
});
window.onbeforeunload = function(){
return 'Are you sure you want to leave?';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment