Always has focus

Tricks the page into thinking it is always focused

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name        Always has focus
// @namespace   dev.tock.keepfocus
// @version     1.0
// @description Tricks the page into thinking it is always focused
// @author      Steve Persson
// @match       *://*/*
// @run-at      document-start
// @grant       unsafeWindow
// @license     MIT
// ==/UserScript==

(function() {
    'use strict';

    // Override the document.hasFocus() method to always return true
    document.hasFocus = function () {
        return true;
    };
    
    // Override the document.hidden property and visibilityState
    Object.defineProperty(Document.prototype, "hidden", { get: () => false });
    Object.defineProperty(Document.prototype, "visibilityState", { get: () => "visible" });

    // Override the Page Visibility API properties
    Object.defineProperty(document, "visibilityState", {
        get: function () {
            return "visible";
        }
    });

    Object.defineProperty(document, "hidden", {
        get: function () {
            return false;
        }
    });

    // Stop propagation of visibilitychange and blur events
    window.addEventListener('visibilitychange', function (event) {
        event.stopImmediatePropagation();
    }, true);

    window.addEventListener('blur', function (event) {
        event.stopImmediatePropagation();
    }, true);

    // Some sites might use window.onfocus/onblur
    window.onblur = null;
    window.onfocus = null;
    
    // Override the window.onblur event handler
    if (unsafeWindow) {
        unsafeWindow.onblur = null;
    }

})();