Izyz-Helper

Help you to use izyz easier!

当前为 2025-01-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Izyz-Helper
  3. // @namespace https://greasyfork.org/users/1417526
  4. // @version 0.0.7
  5. // @description Help you to use izyz easier!
  6. // @author Weichenleeeee
  7. // @match https://www.gdzyz.cn/*
  8. // @icon https://www.gdzyz.cn/assets/weblogo.1b6eba63.svg
  9. // @grant GM_registerMenuCommand
  10. // @grant GM_addStyle
  11. // @grant GM_openInTab
  12. // @grant GM_setValue
  13. // @grant GM_getValue
  14. // @grant GM_xmlhttpRequest
  15. // @grant GM_getResourceText
  16. // @require https://unpkg.com/xlsx/dist/xlsx.full.min.js
  17. // ==/UserScript==
  18.  
  19. (function() {
  20. 'use strict';
  21.  
  22. var names = []; // 用实际的名字替换
  23. var nextButtonEnabled = false; // 是否已点击“添加补录”
  24. var skipButtonEnabled = false; // 是否点击了跳过按钮
  25. var volunteersSkipped = [];
  26.  
  27. // 检测XLSX库是否加载成功
  28. setTimeout(function() {
  29. if (typeof XLSX === "undefined") {
  30. console.error("XLSX 库加载失败!");
  31. alert("无法加载 XLSX 库,功能无法使用!");
  32. return; // 如果加载失败,直接停止脚本
  33. } else {
  34. console.log("XLSX 库加载成功!");
  35. }
  36. }, 1000); // 延迟1秒检查是否加载成功
  37.  
  38. // 添加文件上传按钮
  39. function createFileInput() {
  40. var input = document.createElement('input');
  41. input.type = 'file';
  42. input.accept = '.xlsx,.xls'; // 限制为 Excel 文件
  43. input.style.position = 'fixed';
  44. input.style.bottom = '10px';
  45. input.style.left = '10px';
  46. input.style.zIndex = 9999;
  47. input.style.padding = '5px';
  48. input.style.borderRadius = '5px';
  49. input.style.backgroundColor = '#4CAF50';
  50. input.style.color = 'white';
  51. input.style.border = 'none';
  52. input.style.cursor = 'pointer';
  53. input.addEventListener('change', handleFileSelect);
  54. document.body.appendChild(input);
  55. }
  56. // 添加跳过按钮
  57. function createSkipButton() {
  58. var skipButton = document.createElement('button');
  59. skipButton.textContent = '跳过当前志愿者';
  60. skipButton.style.position = 'fixed';
  61. skipButton.style.bottom = '50px'; // 放在“上传文件”按钮的上方
  62. skipButton.style.left = '10px';
  63. skipButton.style.zIndex = 9999;
  64. skipButton.style.padding = '10px';
  65. skipButton.style.borderRadius = '5px';
  66. skipButton.style.backgroundColor = '#f44336'; // 红色按钮
  67. skipButton.style.color = 'white';
  68. skipButton.style.border = 'none';
  69. skipButton.style.cursor = 'pointer';
  70. skipButton.style.fontSize = '14px';
  71. skipButton.addEventListener('click', function() {
  72. skipButtonEnabled = true; // 设置跳过标志
  73. console.log('用户点击了跳过按钮1');
  74. console.log('skipButtonEnabled is ',skipButtonEnabled);
  75. });
  76. document.body.appendChild(skipButton);
  77. }
  78.  
  79. // 处理文件选择
  80. function handleFileSelect(event) {
  81. var file = event.target.files[0];
  82. if (file && (file.name.endsWith('.xlsx') || file.name.endsWith('.xls'))) {
  83. var reader = new FileReader();
  84. reader.onload = function(e) {
  85. var data = e.target.result;
  86. var workbook = XLSX.read(data, { type: 'binary' });
  87. var sheet = workbook.Sheets[workbook.SheetNames[0]]; // 默认取第一个工作表
  88.  
  89. // 将工作表转换为二维数组,raw: true 确保读取原始数据而不进行格式化
  90. var json = XLSX.utils.sheet_to_json(sheet, { header: 1, raw: true });
  91.  
  92. // 打印原始数据以查看第一行
  93. console.log('读取到的数据:', json);
  94.  
  95. // 获取表头
  96. var header = json[0];
  97. console.log('表头:', header);
  98.  
  99. // 查找"姓名"列的索引,去除每个列名的前后空格
  100. var nameColumnIndex = header.findIndex(col => col.trim() === "姓名");
  101.  
  102. if (nameColumnIndex === -1) {
  103. alert('未找到“姓名”列,请确保Excel中有“姓名”列');
  104. console.error('未找到姓名列');
  105. return;
  106. }
  107.  
  108. // 提取姓名列数据
  109. names = json.slice(1).map(row => row[nameColumnIndex]).filter(name => name);
  110. console.log('已加载姓名:', names);
  111. alert('Excel 文件已成功加载,姓名已提取!');
  112. };
  113. reader.readAsBinaryString(file);
  114. } else {
  115. alert('请上传有效的 Excel 文件');
  116. }
  117. }
  118.  
  119. // 创建并显示进度条
  120. function createProgressBar() {
  121. var progressContainer = document.createElement('div');
  122. progressContainer.style.position = 'fixed';
  123. progressContainer.style.bottom = '90px';
  124. progressContainer.style.left = '10px';
  125. progressContainer.style.zIndex = 9999;
  126. progressContainer.style.width = '300px';
  127. progressContainer.style.height = '30px';
  128. progressContainer.style.backgroundColor = '#e0e0e0';
  129. progressContainer.style.borderRadius = '5px';
  130. var progressBar = document.createElement('div');
  131. progressBar.style.height = '100%';
  132. progressBar.style.width = '0%';
  133. progressBar.style.backgroundColor = '#4CAF50';
  134. progressBar.style.borderRadius = '5px';
  135. progressContainer.appendChild(progressBar);
  136. var progressText = document.createElement('span');
  137. progressText.style.position = 'absolute';
  138. progressText.style.top = '50%';
  139. progressText.style.left = '50%';
  140. progressText.style.transform = 'translate(-50%, -50%)';
  141. progressText.style.color = 'white';
  142. progressText.style.fontSize = '14px';
  143. progressContainer.appendChild(progressText);
  144. var currentVolunteerText = document.createElement('span');
  145. currentVolunteerText.style.position = 'fixed';
  146. currentVolunteerText.style.bottom = '130px';
  147. currentVolunteerText.style.left = '10px';
  148. currentVolunteerText.style.zIndex = 9999;
  149. currentVolunteerText.style.fontSize = '14px';
  150. currentVolunteerText.style.color = '#4CAF50';
  151. currentVolunteerText.style.fontWeight = 'bold';
  152. currentVolunteerText.textContent = '当前录入:第 0 个志愿者';
  153. document.body.appendChild(currentVolunteerText);
  154. document.body.appendChild(progressContainer); // 确保进度条在页面中显示
  155. return { progressBar, progressText, currentVolunteerText };
  156. }
  157.  
  158. // 更新进度条
  159. function updateProgressBar(progressBar, progressText, current, total, currentVolunteerText) {
  160. var percentage = Math.round((current / total) * 100);
  161. progressBar.style.width = percentage + '%';
  162. progressText.textContent = `进度:${percentage}%`;
  163. currentVolunteerText.textContent = `当前录入:第 ${current} 个志愿者`;
  164. }
  165.  
  166.  
  167. // 定义一个函数来模拟点击按钮事件
  168. async function clickButton(selector, delay) {
  169. await new Promise(resolve => setTimeout(resolve, delay));
  170. var button = document.querySelector(selector);
  171. if (button) {
  172. button.click();
  173. console.log(`${selector} 按钮已点击`);
  174. } else {
  175. console.log(`${selector} 按钮未找到`);
  176. }
  177. }
  178.  
  179. // 定义一个函数来输入姓名
  180. async function inputName(name, delay) { // 将 inputText 作为参数传递
  181. await new Promise(resolve => setTimeout(resolve, delay));
  182. let input = document.querySelectorAll('.el-input__inner')[0];
  183. if (input) {
  184. input.value = name; // 使用参数 name 而不是全局变量 inputText
  185. var event = document.createEvent('HTMLEvents');
  186. event.initEvent("input", true, true);
  187. event.eventType = 'message';
  188. input.dispatchEvent(event);
  189. console.log('姓名已输入');
  190. } else {
  191. console.log('文本框未找到');
  192. }
  193. }
  194.  
  195. // 等待用户点击“添加补录”或“跳过”按钮
  196. async function waitForUserAction() {
  197. return new Promise(resolve => {
  198. // 监听跳过按钮
  199. const skipListener = (event) => {
  200. if (skipButtonEnabled) {
  201. console.log('用户点击了跳过按钮2');
  202. resolve('SKIP'); // 返回跳过信号
  203. document.body.removeEventListener('click', skipListener); // 移除跳过按钮监听
  204. }
  205. };
  206.  
  207. // 监听“添加补录”按钮
  208. const nextListener = (event) => {
  209. if (event.target && event.target.matches('button.el-button.el-button--primary span') && event.target.textContent.trim() === '添加补录') {
  210. nextButtonEnabled = true;
  211. console.log('用户点击了“添加补录”按钮');
  212. resolve('CONTINUE'); // 返回继续信号
  213. document.body.removeEventListener('click', nextListener); // 移除添加补录按钮监听
  214. }
  215. };
  216.  
  217. // 为跳过按钮和“添加补录”按钮分别添加监听
  218. document.body.addEventListener('click', skipListener);
  219. document.body.addEventListener('click', nextListener);
  220. });
  221. }
  222.  
  223. // 定义一个函数来勾选单选框并点击“添加补录”
  224. async function checkCheckbox(delay) {
  225. await new Promise(resolve => setTimeout(resolve, delay));
  226. var checkboxes = document.querySelectorAll('.el-checkbox__inner');
  227. if (checkboxes.length > 4) {
  228. console.log('超过4个单选框被找到,等待用户操作');
  229. alert('出现重名,请手动勾选志愿者,并点击“添加补录”');
  230. await waitForUserAction(); // 等待用户点击“添加补录”
  231. }
  232. else if(checkboxes.length < 4){
  233. // 查无此人的情况,需要手动勾选
  234. console.log('查无此人,提供跳过或手动选择的选项');
  235. alert('查无此人,请手动勾选志愿者并点击“添加补录”,或点击“跳过”按钮');
  236. const result = await waitForUserAction(); // 等待用户点击“添加补录”或“跳过”
  237. console.log(result);
  238. if (result === 'SKIP') {
  239. return 'SKIP'; // 跳过当前志愿者
  240. }else if (result === 'CONTINUE') {
  241. return 'CONTINUE';
  242. }
  243. }else{
  244. // 正常情况
  245. checkboxes.forEach((checkbox) => checkbox.click());
  246. console.log('单选框已勾选');
  247. await clickButton('.el-button.el-button--primary[style*="margin-bottom: 20px;"]', 500); // 点击“添加补录”按钮
  248. nextButtonEnabled = true; // 标志已完成“添加补录”
  249. }
  250. }
  251.  
  252. // 主处理函数
  253. async function processNames(names){
  254. const { progressBar, progressText, currentVolunteerText } = createProgressBar(); // 创建进度条
  255. for (let i = 0; i < names.length; i++) {
  256. console.log(`正在处理志愿者:${names[i]}`);
  257. await clickButton('.el-button.el-button--primary', 1000); // 打开输入页面
  258. await inputName(names[i], 1000); // 输入志愿者姓名
  259. await clickButton('.queryOrgBtn', 500); // 点击查询按钮
  260. const result = await checkCheckbox(500);
  261. if (result === 'SKIP') {
  262. console.log(`跳过志愿者:${names[i]}`);
  263. // 记录当前志愿者的名字
  264. volunteersSkipped.push(names[i]);
  265. console.log(`记录志愿者:${names[i]}`);
  266. continue; // 跳过当前志愿者,进入下一个
  267. }else if (result === 'CONTINUE') {
  268. console.log(`继续处理志愿者:${names[i]}`);
  269. }
  270. // 更新进度条
  271. updateProgressBar(progressBar, progressText, i + 1, names.length, currentVolunteerText);
  272. // 等待用户完成“添加补录”操作
  273. await clickButton('.el-button.el-button--primary[style*="display: block; margin: 0px auto;"]', 500); // 点击“下一步”按钮
  274. console.log('“下一步”已被点击');
  275. nextButtonEnabled = false; // 重置标志
  276. };
  277. // 在最后显示被跳过的志愿者名字
  278. if (volunteersSkipped.length > 0) {
  279. alert(`录用完成,被跳过的的志愿者:${volunteersSkipped.join(', ')}`);
  280. }
  281. }
  282.  
  283. // 创建按钮
  284. createFileInput();
  285. createSkipButton();
  286.  
  287. // 定义菜单命令:开始
  288. let menu1 = GM_registerMenuCommand('开始', function () {
  289. if (names.length === 0) {
  290. alert('请先上传并加载 Excel 文件!');
  291. return;
  292. }
  293. processNames(names);
  294. }, 'o');
  295.  
  296. })();