Skip to content

Instantly share code, notes, and snippets.

@ChieftainY2k
Last active September 21, 2023 07:34
Show Gist options
  • Save ChieftainY2k/4dcad596a1fa23f4301158ed7efd24cd to your computer and use it in GitHub Desktop.
Save ChieftainY2k/4dcad596a1fa23f4301158ed7efd24cd to your computer and use it in GitHub Desktop.
Bookmarklet to disable visibility change events (to keep websites playing content even when out of focus) (based on https://greasyfork.org/en/scripts/429635-always-on-focus/code )
javascript:(function(){window.onblur=null;window.blurred=false;Object.defineProperty(document,"hasFocus",{get:function(){return true}});Object.defineProperty(document,"webkitHidden",{get:function(){return false}});["hidden","mozHidden","msHidden","webkitHidden"].forEach(function(t){Object.defineProperty(document,t,{value:false,configurable:true})});["visibilitychange","webkitvisibilitychange","mozvisibilitychange","msvisibilitychange"].forEach(function(t){document.removeEventListener(t,document["on"+t])});var e=function(t){["blur","mouseleave","mouseout"].includes(t.type)&&(t.target instanceof HTMLInputElement||t.target instanceof HTMLAnchorElement||t.target instanceof HTMLSpanElement)&&t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation()};["blur","mouseleave","mouseout"].forEach(function(t){window.addEventListener(t,e,true),document.addEventListener(t,e,true)})})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment