Remove mouse restrictions and automatically close pop-up windows

Auto Close Popups for Learning Site & Block Mouse Leave Popup Improved

目前为 2024-11-07 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Remove mouse restrictions and automatically close pop-up windows
  3. // @namespace https://mbt.jd.com/cards/ffksimple/home.html?channelName=wdqb_sy_icon&do_not_click_on_me
  4. // @namespace https://t.me/mycutcbot
  5. // @version 0.21
  6. // @description Auto Close Popups for Learning Site & Block Mouse Leave Popup Improved
  7. // @author ziqs
  8. // @match *://*.study.moxueyuan.com/*
  9. // @grant none
  10. // @license GPL-3.0-or-later
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // 定義一個阻止事件的函數
  17. function preventEvent(e) {
  18. e.stopImmediatePropagation();
  19. e.preventDefault();
  20. }
  21.  
  22. // 監聽 `mouseleave`, `mouseout`, 和 `blur` 事件
  23. ['mouseleave', 'mouseout', 'blur'].forEach(eventType => {
  24. window.addEventListener(eventType, preventEvent, true);
  25. document.addEventListener(eventType, preventEvent, true);
  26. });
  27.  
  28. // 定時移除動態新增的事件監聽器
  29. const observer = new MutationObserver(() => {
  30. document.querySelectorAll('*').forEach(element => {
  31. try {
  32. element.onmouseleave = null;
  33. element.onmouseout = null;
  34. element.onblur = null;
  35. } catch (error) {
  36. console.error(`Error clearing event listeners on ${element}`, error);
  37. }
  38. });
  39. });
  40.  
  41. // 開始監聽 DOM 變化
  42. observer.observe(document.body, { childList: true, subtree: true });
  43.  
  44. })();
  45.  
  46.  
  47.  
  48. (function() {
  49. 'use strict';
  50.  
  51. // 監聽 <body> 的類別名稱變化
  52. const observer = new MutationObserver((mutationsList) => {
  53. for (const mutation of mutationsList) {
  54. if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
  55. const bodyClass = document.body.className;
  56.  
  57. // 檢查是否包含 el-popup-parent--hidden 類
  58. if (bodyClass.includes('el-popup-parent--hidden')) {
  59. console.log('Popup detected, attempting to click "I am here" button after delay');
  60.  
  61. // 延遲 5 秒點擊按鈕
  62. setTimeout(() => {
  63. // 尋找所有符合條件的按鈕
  64. const buttons = document.querySelectorAll('.dialog-footer-cancel');
  65. for (const button of buttons) {
  66. if (button.textContent.includes('我在')) {
  67. button.click();
  68. console.log('"I am here" button clicked after 5 seconds');
  69. break;
  70. }
  71. }
  72. }, 5000); // 5秒延遲(5000毫秒)
  73. }
  74. }
  75. }
  76. });
  77.  
  78. // 開始監聽 <body> 的屬性變化
  79. observer.observe(document.body, { attributes: true });
  80.  
  81. })();