D11125127

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

  1. // ==UserScript==
  2. // @name D11125127
  3. // @namespace http://tampermonkey.net/
  4. // @version 4.0.0
  5. // @description 完整解鎖考試限制,防止跳出視窗,允許正常答題。
  6. // @author YourName
  7. // @match https://ecampus.takming.edu.tw/*
  8. // @grant none
  9. // @run-at document-start
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. console.log("最終修正版解鎖腳本啟動...");
  16.  
  17. // 禁止 alert, confirm, prompt
  18. const disableAlerts = () => {
  19. window.alert = () => {};
  20. window.confirm = () => true;
  21. window.prompt = () => '';
  22. console.log("已禁用 alert, confirm, prompt!");
  23. };
  24.  
  25. // 覆寫窗口事件
  26. const overrideWindowEvents = () => {
  27. window.onbeforeunload = null;
  28. document.onvisibilitychange = null;
  29. window.onblur = null;
  30. window.onfocus = null;
  31.  
  32. const events = ['beforeunload', 'visibilitychange', 'blur', 'focus'];
  33. events.forEach(event => {
  34. window.addEventListener(event, e => e.stopImmediatePropagation(), true);
  35. });
  36.  
  37. console.log("已覆寫窗口事件!");
  38. };
  39.  
  40. // 攔截核心請求並確保正常運作
  41. const interceptRequests = () => {
  42. const originalXHROpen = XMLHttpRequest.prototype.open;
  43.  
  44. XMLHttpRequest.prototype.open = function (method, url, ...args) {
  45. if (url.includes('item_fetch.php')) {
  46. console.log("攔截並監控核心請求:", url);
  47. this.addEventListener('readystatechange', function () {
  48. if (this.readyState === 4) {
  49. console.log("核心請求完成:", this.responseText);
  50. }
  51. });
  52. }
  53. return originalXHROpen.apply(this, [method, url, ...args]);
  54. };
  55.  
  56. console.log("核心請求攔截完成!");
  57. };
  58.  
  59. // 初始化
  60. const init = () => {
  61. disableAlerts();
  62. overrideWindowEvents();
  63. interceptRequests();
  64. console.log("所有功能已啟用,頁面限制已解除!");
  65. };
  66.  
  67. // 等待 DOM 加載完成後執行
  68. if (document.readyState === 'complete' || document.readyState === 'interactive') {
  69. init();
  70. } else {
  71. document.addEventListener('DOMContentLoaded', init);
  72. }
  73. })();