Auto Close Popup and Random Click

Close popup, monitor elements, and randomly click elements on page navigation.

目前为 2024-12-30 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Auto Close Popup and Random Click
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.3
  5. // @description Close popup, monitor elements, and randomly click elements on page navigation.
  6. // @author Your Name
  7. // @match https://ucontent.unipus.cn/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15.  
  16. const max_lesson_nums = 32;
  17. let randomClickTimeout = null;
  18.  
  19. // Function to close the popup
  20. function closePopup() {
  21. const interval = setInterval(() => {
  22. try {
  23. const closeButton = document.querySelector(".dialog-header-pc--close-yD7oN");
  24. if (closeButton) {
  25. closeButton.click();
  26. console.log("Popup close button clicked.");
  27. }
  28.  
  29. const dialogButton = document.querySelector("div.dialog-header-pc--dialog-header-2qsXD")?.parentElement?.querySelector("button");
  30. if (dialogButton) {
  31. dialogButton.click();
  32. console.log("Dialog button clicked.");
  33. }
  34.  
  35. // Check if popup is closed
  36. if (!document.querySelector(".dialog-header-pc--close-yD7oN") &&
  37. !document.querySelector("div.dialog-header-pc--dialog-header-2qsXD")) {
  38. clearInterval(interval);
  39. console.log("Popup closed successfully.");
  40. }
  41. } catch (error) {
  42. console.error("Error attempting to close popup:", error);
  43. }
  44. }, 500); // Check every 500ms
  45. }
  46.  
  47. // Function to monitor and click .ant-btn-primary
  48. function monitorPrimaryButton() {
  49. const interval = setInterval(() => {
  50. try {
  51. const primaryButton = document.querySelector(".ant-btn-primary");
  52. if (primaryButton) {
  53. primaryButton.click();
  54. console.log("Primary button clicked.");
  55. clearInterval(interval);
  56. }
  57. } catch (error) {
  58. console.error("Error attempting to click primary button:", error);
  59. }
  60. }, 500); // Check every 500ms
  61. }
  62.  
  63. // Function to randomly click elements
  64. function randomClick() {
  65. const elements = Array.from(document.querySelectorAll(".pc-menu-node-name"));
  66. if (elements.length > max_lesson_nums) {
  67. const first = elements.slice(0, max_lesson_nums);
  68. const randomIndex = Math.floor(Math.random() * first.length);
  69. first[randomIndex].click();
  70. console.log(`Clicked element at index ${randomIndex}`);
  71. } else {
  72. console.warn(`Less than ${max_lesson_nums} elements found.`);
  73. }
  74. }
  75.  
  76. // Function to start the random click loop
  77. function startRandomClickLoop() {
  78. if (randomClickTimeout) {
  79. clearTimeout(randomClickTimeout);
  80. }
  81.  
  82. const randomInterval = Math.floor(Math.random() * (4 * 60 * 1000 - 1 * 60 * 1000) + 1 * 60 * 1000); // 1-4 minutes in ms
  83. console.log(`Next click in ${randomInterval / 1000} seconds.`);
  84.  
  85. randomClickTimeout = setTimeout(() => {
  86. randomClick();
  87. startRandomClickLoop(); // Restart the loop
  88. }, randomInterval);
  89. }
  90.  
  91. // Observe URL changes
  92. let lastUrl = location.href;
  93. const observer = new MutationObserver(() => {
  94. if (location.href !== lastUrl) {
  95. console.log("URL changed to", location.href);
  96. lastUrl = location.href;
  97.  
  98. closePopup();
  99. monitorPrimaryButton();
  100. startRandomClickLoop();
  101. }
  102. });
  103.  
  104. observer.observe(document, { childList: true, subtree: true });
  105. })();

QingJ © 2025

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