Stripchat Always Focus

Keeps Stripchat visible optimally (Combines best of v1.1 & v1.2)

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Stripchat Always Focus
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  Keeps Stripchat visible optimally (Combines best of v1.1 & v1.2)
// @author       Nam
// @match        *://stripchat.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function () {
    'use strict';

    // Ưu điểm từ bản v1.2: Ghi đè bằng getter tự nhiên
    Object.defineProperty(document, 'hidden', {
        configurable: true,
        get: () => false
    });

    Object.defineProperty(document, 'visibilityState', {
        configurable: true,
        get: () => 'visible'
    });

    Document.prototype.hasFocus = function () {
        return true;
    };

    // Ưu điểm từ bản v1.1: Chặn tín hiệu gửi đến trang web khi đổi tab
    const visibilityEvents = ['visibilitychange', 'webkitvisibilitychange'];
    for (let eventName of visibilityEvents) {
        window.addEventListener(eventName, function(event) {
            event.stopImmediatePropagation();
        }, true);
        document.addEventListener(eventName, function(event) {
            event.stopImmediatePropagation();
        }, true);
    }

    window.addEventListener('blur', function(event) {
        if (event.target === window || event.target === document) {
            event.stopImmediatePropagation();
        }
    }, true);
})();