Stripchat Always Focus

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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