lchanouha / Disable Page Visibility API

// ==UserScript==
// @name         Disable Page Visibility API
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Disables JS events on whole page focus/unfocus. Usefull to prevent ads stop when switching to another tab.
// @author       Louis Chanouha
// @match        *://*/*
// @grant        none
// @license MIT
// ==/UserScript==

// Sourced from: https://stackoverflow.com/questions/47660653/chrome-extension-how-to-disable-page-visibility-api
// Tested on Google Chrome 64 / Tampermonkey (24/03/2018)
// Référence; https://gist.github.com/lchanouha/06b51423bc60693af216ebdce37d86a8

for (event_name of ["visibilitychange", "webkitvisibilitychange", "blur"]) {
  window.addEventListener(event_name, function(event) {
        event.stopImmediatePropagation();
    }, true);
}