自动填充闯关

自动填充全国大学生职业规划大赛生涯闯关系统

  1. // ==UserScript==
  2. // @name 自动填充闯关
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.9
  5. // @description 自动填充全国大学生职业规划大赛生涯闯关系统
  6. // @author BaoPaper
  7. // @match https://zgs.chsi.com.cn/*
  8. // @grant GM_xmlhttpRequest
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // 监听快捷键 b 按下事件
  16. document.addEventListener('keydown', function(event) {
  17. if (event.key === 'b' || event.key === 'B') {
  18. // 阻止默认事件,防止 e 键被浏览器处理
  19. event.preventDefault();
  20.  
  21. // 执行所有功能
  22. fillInputsAndTextareas();
  23. }
  24. });
  25.  
  26. // 执行所有功能
  27. function fillInputsAndTextareas() {
  28. // 设置所有 input 的值为 123 或根据 placeholder 填充
  29. const inputs = document.querySelectorAll('input');
  30. inputs.forEach(input => {
  31. if (input.type !== 'checkbox' && input.type !== 'radio' && input.type !== 'button') {
  32. const placeholder = input.getAttribute('placeholder');
  33. const lengthMatch = placeholder && placeholder.match(/\((\d+)~(\d+)字\)/);
  34.  
  35. if (lengthMatch) {
  36. // 如果有字数范围,生成相应长度的随机字符
  37. const minLength = parseInt(lengthMatch[1]);
  38. const maxLength = parseInt(lengthMatch[2]);
  39. const randomLength = Math.floor(Math.random() * (maxLength - minLength + 1)) + minLength;
  40. const randomText = generateRandomText(randomLength);
  41.  
  42. const setter = Object.getOwnPropertyDescriptor(
  43. Object.getPrototypeOf(input),
  44. 'value'
  45. ).set;
  46. setter.call(input, randomText);
  47.  
  48. let inputEvent = new Event('input', {
  49. 'bubbles': true,
  50. 'cancelable': true,
  51. 'composed': true
  52. });
  53. input.dispatchEvent(inputEvent);
  54. } else {
  55. // 如果没有字数范围,直接填充 "123"
  56. const setter = Object.getOwnPropertyDescriptor(
  57. Object.getPrototypeOf(input),
  58. 'value'
  59. ).set;
  60. setter.call(input, '123');
  61.  
  62. let inputEvent = new Event('input', {
  63. 'bubbles': true,
  64. 'cancelable': true,
  65. 'composed': true
  66. });
  67. input.dispatchEvent(inputEvent);
  68. }
  69. }
  70. });
  71.  
  72. // 为每个符合条件的 textarea 根据 placeholder 填充对应长度的随机文本
  73. const textareas = document.querySelectorAll('textarea[placeholder*="请输入"]');
  74. textareas.forEach(textarea => {
  75. const placeholder = textarea.getAttribute('placeholder');
  76. const match = placeholder.match(/\((\d+)~(\d+)字\)/);
  77.  
  78. if (match) {
  79. const minLength = parseInt(match[1]);
  80. const maxLength = parseInt(match[2]);
  81. const randomLength = Math.floor(Math.random() * (maxLength - minLength + 1)) + minLength;
  82.  
  83. // 生成指定长度的随机文本
  84. const randomText = generateRandomText(randomLength);
  85.  
  86. // 设置 textarea 的值
  87. const setter = Object.getOwnPropertyDescriptor(
  88. Object.getPrototypeOf(textarea),
  89. 'value'
  90. ).set;
  91. setter.call(textarea, randomText);
  92.  
  93. // 创建并触发 input 事件,模拟用户输入
  94. let event = new Event('input', {
  95. 'bubbles': true,
  96. 'cancelable': true
  97. });
  98. textarea.dispatchEvent(event);
  99. }
  100. });
  101.  
  102. // 为每个符合条件的 input 获取独立的人名并填充
  103. const nameInputs = document.querySelectorAll('input[placeholder="请输入(2~10字)"]');
  104. nameInputs.forEach((input, index) => {
  105. GM_xmlhttpRequest({
  106. method: 'GET',
  107. url: 'https://api.mir6.com/api/sjname',
  108. onload: function(response) {
  109. const name = response.responseText.trim();
  110. const setter = Object.getOwnPropertyDescriptor(
  111. Object.getPrototypeOf(input),
  112. 'value'
  113. ).set;
  114. setter.call(input, name);
  115.  
  116. let event = new Event('input', {
  117. 'bubbles': true,
  118. 'cancelable': true
  119. });
  120. input.dispatchEvent(event);
  121. },
  122. onerror: function(error) {
  123. console.error(`API 请求失败 for input ${index + 1}:`, error);
  124. }
  125. });
  126. });
  127. }
  128.  
  129. // 生成指定长度的随机文本
  130. function generateRandomText(length) {
  131. const characters = '你我它是好哈。?!';
  132. let text = '';
  133. for (let i = 0; i < length; i++) {
  134. text += characters.charAt(Math.floor(Math.random() * characters.length));
  135. }
  136. return text;
  137. }
  138.  
  139. // 留给你空间继续编写代码
  140. // TODO: 在此添加新的功能代码
  141.  
  142. })();

QingJ © 2025

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