您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Block websites from knowing if you switched tabs/windows
- // ==UserScript==
- // @name PreventPageVisibility
- // @namespace https://github.com/IceWreck
- // @match *://*/*
- // @run-at document-start
- // @grant none
- // @version 1.1
- // @author IceWreck
- // @description Block websites from knowing if you switched tabs/windows
- // ==/UserScript==
- // This userscript blocks the page visibility API and to some extent the old blur/focus APIs.
- let events_to_block = [
- "visibilitychange",
- "webkitvisibilitychange",
- "mozvisibilitychange",
- "hasFocus",
- "blur",
- "focus",
- "mouseleave"
- ]
- for (event_name of events_to_block) {
- document.addEventListener(event_name, function (event) {
- event.preventDefault();
- event.stopPropagation();
- event.stopImmediatePropagation();
- }, true);
- }
- for (event_name of events_to_block) {
- window.addEventListener(event_name, function (event) {
- event.preventDefault();
- event.stopPropagation();
- event.stopImmediatePropagation();
- }, true);
- }
- document.hasFocus = function () { return true; };
- document.onvisibilitychange = null;
- Object.defineProperty(document, "visibilityState", { value: "visible" });
- Object.defineProperty(document, "hidden", { value: false });
- Object.defineProperty(document, "mozHidden", { value: false });
- Object.defineProperty(document, "webkitHidden", { value: false });
- Object.defineProperty(document, "webkitVisibilityState", { value: "visible" });