D11125127

完整解鎖考試限制,防止跳出視窗,允許正常答題。

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         D11125127
// @namespace    http://tampermonkey.net/
// @version      4.0.0
// @description  完整解鎖考試限制,防止跳出視窗,允許正常答題。
// @author       YourName
// @match        https://ecampus.takming.edu.tw/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function () {
    'use strict';

    console.log("最終修正版解鎖腳本啟動...");

    // 禁止 alert, confirm, prompt
    const disableAlerts = () => {
        window.alert = () => {};
        window.confirm = () => true;
        window.prompt = () => '';
        console.log("已禁用 alert, confirm, prompt!");
    };

    // 覆寫窗口事件
    const overrideWindowEvents = () => {
        window.onbeforeunload = null;
        document.onvisibilitychange = null;
        window.onblur = null;
        window.onfocus = null;

        const events = ['beforeunload', 'visibilitychange', 'blur', 'focus'];
        events.forEach(event => {
            window.addEventListener(event, e => e.stopImmediatePropagation(), true);
        });

        console.log("已覆寫窗口事件!");
    };

    // 攔截核心請求並確保正常運作
    const interceptRequests = () => {
        const originalXHROpen = XMLHttpRequest.prototype.open;

        XMLHttpRequest.prototype.open = function (method, url, ...args) {
            if (url.includes('item_fetch.php')) {
                console.log("攔截並監控核心請求:", url);
                this.addEventListener('readystatechange', function () {
                    if (this.readyState === 4) {
                        console.log("核心請求完成:", this.responseText);
                    }
                });
            }
            return originalXHROpen.apply(this, [method, url, ...args]);
        };

        console.log("核心請求攔截完成!");
    };

    // 初始化
    const init = () => {
        disableAlerts();
        overrideWindowEvents();
        interceptRequests();
        console.log("所有功能已啟用,頁面限制已解除!");
    };

    // 等待 DOM 加載完成後執行
    if (document.readyState === 'complete' || document.readyState === 'interactive') {
        init();
    } else {
        document.addEventListener('DOMContentLoaded', init);
    }
})();