Stripchat Always Focus

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

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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.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);
})();