鼠标离开监听禁用

禁止网页检测鼠标是否离开页面,保护用户隐私

目前為 2025-04-01 提交的版本,檢視 最新版本

// ==UserScript==
// @name         鼠标离开监听禁用
// @namespace    http://tampermonkey.net/
// @version      v0.2
// @description  禁止网页检测鼠标是否离开页面,保护用户隐私
// @author       你自己
// @match        https://mooc1.chaoxing.com/exam-ans/exam/test/look?courseId=205862551&classId=114190604&examId=6561813&examAnswerId=0&cpi=355895000
// @match        https://mooc1.chaoxing.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=chaoxing.com
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // 1. 阻止 mouseout 和 mouseleave 事件
    ['mouseout', 'mouseleave'].forEach(eventName => {
        document.addEventListener(eventName, function(event) {
            event.stopPropagation();
            event.preventDefault();
        }, { capture: true, passive: false });
    });

    // 2. 阻止 window 的 blur 和 focusout 事件
    ['blur', 'focusout'].forEach(eventName => {
        window.addEventListener(eventName, function(event) {
            event.stopPropagation();
            event.preventDefault();
        }, { capture: true, passive: false });
    });

    // 3. 伪造页面可见性状态
    Object.defineProperty(document, 'visibilityState', {
        get: function() {
            return 'visible'; // 始终返回页面可见
        },
        configurable: true
    });
    Object.defineProperty(document, 'hidden', {
        get: function() {
            return false; // 始终返回未隐藏
        },
        configurable: true
    });

    // 4. 拦截 visibilitychange 事件
    document.addEventListener('visibilitychange', function(event) {
        event.stopPropagation();
        event.preventDefault();
    }, { capture: true, passive: false });

    // 5. 阻止页面检测鼠标坐标超出窗口
    const fakeMouseEvent = new MouseEvent('mousemove', {
        clientX: 100,
        clientY: 100,
        bubbles: true,
        cancelable: true
    });
    setInterval(function() {
        document.dispatchEvent(fakeMouseEvent); // 定期模拟鼠标移动
    }, 60000); // 每60秒触发一次,模拟用户活跃

    // 6. 重写 window.onblur 和 window.onfocus
    window.onblur = function() { return false; };
    window.onfocus = function() { return true; };

    // 7. 防止通过 document.hasFocus() 检测
    Document.prototype.hasFocus = function() {
        return true; // 始终返回页面有焦点
    };

    console.log('鼠标离开监听已禁用');
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址