Stripchat Always Focus

tricks the website into thinking the tab is always active and visible

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Stripchat Always Focus
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  tricks the website into thinking the tab is always active and visible
// @author       Nam
// @match        *://stripchat.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    Object.defineProperty(document, 'hidden', { value: false, writable: false });
    Object.defineProperty(document, 'visibilityState', { value: 'visible', writable: false });
    Document.prototype.hasFocus = function() { return true; };

    const blockEvents = ['visibilitychange', 'webkitvisibilitychange', 'blur', 'mouseleave'];

    for (let eventName of blockEvents) {
        window.addEventListener(eventName, function(event) {
            event.stopImmediatePropagation();
        }, true);
        document.addEventListener(eventName, function(event) {
            event.stopImmediatePropagation();
        }, true);
    }
})();