返回列表 发布新帖
查看: 70|回复: 0

gcp44自动重试脚本

发表于 昨天 22:34 | 查看全部 |阅读模式

立刻注册账号,享受更清爽的界面!

您需要 登录 才可以下载或查看,没有账号?注册

×
不知道为啥我一直44,在想道是不是卡的问题,我用的infini ,号也是是五六年的老号,经常用,等夜晚试试换bybit看看
隔壁论坛的大佬说是玄学,有的人infini成功了的。gcp分为aistudio和vertexai,其中aistudio是大部分人使用的
cf229811baa48ff93f4de6701082f8cd.jpg
看样子是共用300美金,总共是1000赠金的vertexai和300的初始送的,我是看别的佬友帖子图片显示的

  1. // ==UserScript==
  2. // [url=home.php?mod=space&uid=4014]@name[/url]         Google Cloud 注册流程自动化
  3. // @namespace    http://tampermonkey.net/
  4. // @version      2.0
  5. // @description  自动点击"同意並繼續",然后"免費試用",如果出现"確定"则刷新重试。
  6. // @author       Your Name
  7. // @match        https://console.cloud.google.com/freetrial/signup/*
  8. // @grant        GM_setValue
  9. // @grant        GM_getValue
  10. // @run-at       document-idle
  11. // ==/UserScript==

  12. (function() {
  13.     'use strict';

  14.     // --- 配置 ---
  15.     const XPATH_BUTTON_AGREE = "//button[.//span[normalize-space(.)='同意並繼續']]"; // 第一个按钮
  16.     const XPATH_BUTTON_FREE_TRIAL = "//button[.//span[normalize-space(.)='免費試用']]"; // 第二个按钮
  17.     const XPATH_BUTTON_CONFIRM = "//button[.//span[normalize-space(.)='確定']]";    // 第三个按钮 (检查用)

  18.     const WAIT_TIMEOUT_MS = 30000;      // 等待按钮出现的最大时间 (毫秒, 30秒)
  19.     const POST_CLICK_DELAY_MIN_MS = 1000; // 点击后等待的最小时间 (毫秒)
  20.     const POST_CLICK_DELAY_MAX_MS = 2000; // 点击后等待的最大时间 (毫秒)
  21.     const CONFIRM_CHECK_TIMEOUT_MS = 5000; // 点击免费试用后,检查确定按钮出现的时间窗口 (毫秒, 5秒)

  22.     // 使用 GM_* 函数来持久化运行状态,以便刷新后能自动重启
  23.     const STORAGE_KEY_RUNNING = 'googleCloudAutoClickerRunning';

  24.     let isRunning = false;      // 当前脚本是否激活运行
  25.     let controlButton = null;   // 控制按钮的引用

  26.     // --- 帮助函数 ---

  27.     function log(message) {
  28.         console.log(`[AutoClicker] ${message}`);
  29.     }
  30.     function logWarn(message) {
  31.         console.warn(`[AutoClicker] ${message}`);
  32.     }
  33.     function logError(message) {
  34.         console.error(`[AutoClicker] ${message}`);
  35.     }

  36.     // 等待函数
  37.     function wait(ms) {
  38.         return new Promise(resolve => setTimeout(resolve, ms));
  39.     }

  40.     // 获取随机延迟
  41.     function getRandomDelay(min = POST_CLICK_DELAY_MIN_MS, max = POST_CLICK_DELAY_MAX_MS) {
  42.         return Math.random() * (max - min) + min;
  43.     }

  44.     // 查找元素,带超时和可见性检查
  45.     async function findElement(xpath, timeout = WAIT_TIMEOUT_MS) {
  46.         log(`查找元素 (超时 ${timeout / 1000}s): ${xpath}`);
  47.         const startTime = Date.now();
  48.         while (Date.now() - startTime < timeout) {
  49.             if (!isRunning) return null; // 如果中途停止了,返回 null

  50.             try {
  51.                 const result = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  52.                 const element = result.singleNodeValue;
  53.                 // 检查元素是否存在且可见 (offsetParent !== null 是一个常用但不完美的检查)
  54.                 if (element && element.offsetParent !== null) {
  55.                     log(`元素找到: ${xpath}`);
  56.                     return element;
  57.                 }
  58.             } catch (error) {
  59.                 logError(`查找元素时 XPath 出错: ${xpath} - ${error}`);
  60.                 return null; // XPath 错误,停止查找
  61.             }
  62.             await wait(250); // 每 250ms 检查一次
  63.         }
  64.         logWarn(`查找元素超时 (${timeout / 1000}s): ${xpath}`);
  65.         return null; // 超时未找到
  66.     }

  67.      // 仅检查元素是否存在,不长时间等待
  68.     function checkElementExists(xpath) {
  69.         try {
  70.             const result = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  71.             return result.singleNodeValue !== null;
  72.         } catch (error) {
  73.             logError(`检查元素存在性时 XPath 出错: ${xpath} - ${error}`);
  74.             return false;
  75.         }
  76.     }

  77.     // 安全点击元素 (包括尝试 JS 点击)
  78.     function clickElement(element, elementName) {
  79.         try {
  80.             log(`尝试点击 '${elementName}'...`);
  81.             element.click();
  82.             log(`'${elementName}' 点击成功。`);
  83.             return true;
  84.         } catch (e) {
  85.              logError(`点击 '${elementName}' 时出错: ${e}`);
  86.              logWarn(`尝试使用 JS 点击 '${elementName}'...`);
  87.              try {
  88.                  element.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true }));
  89.                  log(`'${elementName}' JS 点击成功。`);
  90.                  return true;
  91.              } catch (jsE) {
  92.                  logError(`JS 点击 '${elementName}' 也失败: ${jsE}`);
  93.                  return false;
  94.              }
  95.         }
  96.     }

  97.     // 刷新页面
  98.     function refreshPage() {
  99.         log("准备刷新页面...");
  100.         if (isRunning) { // 只有在脚本激活状态下才执行刷新
  101.             log("正在刷新...");
  102.             // 在刷新前确保状态已保存为 true (如果 stopLoop 没有被意外调用)
  103.             GM_setValue(STORAGE_KEY_RUNNING, true);
  104.             setTimeout(() => window.location.reload(), 500); // 短暂延迟后刷新
  105.         } else {
  106.             logWarn("脚本已停止,取消刷新。");
  107.         }
  108.     }

  109.     // --- 主要工作流程 ---
  110.     async function mainWorkflow() {
  111.         if (!isRunning) return;
  112.         log("=== 开始新流程 ===");

  113.         // --- 步骤 1: 点击 "同意並繼續" ---
  114.         const buttonAgree = await findElement(XPATH_BUTTON_AGREE);
  115.         if (!buttonAgree) {
  116.             logError("找不到 '同意並繼續' 按钮。可能是页面结构变化或未加载。停止流程。");
  117.             stopLoop(); // 停止,不刷新,让用户检查
  118.             alert("自动点击器:找不到 '同意並繼續' 按钮,脚本已停止。");
  119.             return;
  120.         }
  121.         if (!clickElement(buttonAgree, "同意並繼續")) {
  122.             logError("点击 '同意並繼續' 失败。停止流程。");
  123.             stopLoop();
  124.             alert("自动点击器:点击 '同意並繼續' 失败,脚本已停止。");
  125.             return;
  126.         }

  127.         // --- 步骤 2: 等待并点击 "免費試用" ---
  128.         const buttonFreeTrial = await findElement(XPATH_BUTTON_FREE_TRIAL);
  129.         if (!buttonFreeTrial) {
  130.             logError(`'免費試用' 按钮未在 ${WAIT_TIMEOUT_MS / 1000} 秒内出现。刷新页面重试...`);
  131.             refreshPage(); // 未找到则刷新重试
  132.             return;
  133.         }
  134.         if (!clickElement(buttonFreeTrial, "免費試用")) {
  135.             logError("点击 '免費試用' 失败。刷新页面重试...");
  136.             refreshPage(); // 点击失败也刷新重试
  137.             return;
  138.         }

  139.         // --- 步骤 3: 点击后等待 1-2 秒 ---
  140.         const delay = getRandomDelay();
  141.         log(`等待 ${delay.toFixed(0)} 毫秒...`);
  142.         await wait(delay);
  143.         if (!isRunning) return; // 检查是否在等待期间被停止

  144.         // --- 步骤 4: 检查 "確定" 按钮是否在短时间内出现 ---
  145.         log(`检查 '確定' 按钮是否在 ${CONFIRM_CHECK_TIMEOUT_MS / 1000} 秒内出现...`);
  146.         let confirmButtonFound = false;
  147.         const checkStartTime = Date.now();
  148.         while (Date.now() - checkStartTime < CONFIRM_CHECK_TIMEOUT_MS) {
  149.              if (!isRunning) return; // 检查是否在等待期间被停止
  150.              if (checkElementExists(XPATH_BUTTON_CONFIRM)) {
  151.                  log("'確定' 按钮已找到!符合预期,准备刷新页面重新开始。");
  152.                  confirmButtonFound = true;
  153.                  break;
  154.              }
  155.              await wait(200); // 短暂等待再次检查
  156.         }

  157.         // --- 步骤 5: 根据是否找到 "確定" 按钮决定操作 ---
  158.         if (confirmButtonFound) {
  159.             // 如果找到了 "確定",说明流程按预期进行到了需要刷新的步骤
  160.             refreshPage();
  161.         } else {
  162.             // 如果在检查时间内 *没有* 找到 "確定" 按钮
  163.             logWarn(`在 ${CONFIRM_CHECK_TIMEOUT_MS / 1000} 秒内未检测到 '確定' 按钮。这可能意味着流程卡住或有变化。将刷新页面重试。`);
  164.             // 即使没找到,也按你的要求刷新重试
  165.             refreshPage();
  166.         }
  167.     }

  168.     // --- 控制逻辑 ---
  169.     function startLoop() {
  170.         if (isRunning) {
  171.             log("流程已经在运行中。");
  172.             return;
  173.         }
  174.         log("=== 启动自动流程 ===");
  175.         isRunning = true;
  176.         GM_setValue(STORAGE_KEY_RUNNING, true); // 保存状态
  177.         if (controlButton) {
  178.             controlButton.textContent = '停止流程 (运行中)';
  179.             controlButton.style.backgroundColor = '#dc3545';
  180.         }
  181.         mainWorkflow(); // 启动流程
  182.     }

  183.     function stopLoop() {
  184.         if (!isRunning && GM_getValue(STORAGE_KEY_RUNNING, false) === false) {
  185.              log("流程并未运行。");
  186.              return; // 如果已经是停止状态,则不执行任何操作
  187.         }
  188.         log("=== 停止自动流程 ===");
  189.         isRunning = false;
  190.         GM_setValue(STORAGE_KEY_RUNNING, false); // 保存状态
  191.         if (controlButton) {
  192.             controlButton.textContent = '开始自动流程';
  193.             controlButton.style.backgroundColor = '#28a745';
  194.         }
  195.         // 不需要清除延时,因为 async 函数中的 await 会在 isRunning 变为 false 时自然退出循环
  196.     }

  197.     // --- 创建控制按钮 ---
  198.     function createControlButton() {
  199.         if (document.getElementById('autoClickerControlButton')) return; // 防止重复创建

  200.         controlButton = document.createElement('button');
  201.         controlButton.id = 'autoClickerControlButton';
  202.         controlButton.style.position = 'fixed';
  203.         controlButton.style.bottom = '20px';
  204.         controlButton.style.right = '20px';
  205.         controlButton.style.zIndex = '9999';
  206.         controlButton.style.padding = '10px 15px';
  207.         controlButton.style.color = 'white';
  208.         controlButton.style.border = 'none';
  209.         controlButton.style.borderRadius = '5px';
  210.         controlButton.style.cursor = 'pointer';
  211.         controlButton.style.fontSize = '14px';
  212.         controlButton.style.boxShadow = '0 2px 5px rgba(0,0,0,0.2)';

  213.         // 初始化按钮状态
  214.         if (GM_getValue(STORAGE_KEY_RUNNING, false)) {
  215.             controlButton.textContent = '停止流程 (运行中)';
  216.             controlButton.style.backgroundColor = '#dc3545';
  217.         } else {
  218.             controlButton.textContent = '开始自动流程';
  219.             controlButton.style.backgroundColor = '#28a745';
  220.         }

  221.         controlButton.addEventListener('click', () => {
  222.             // 读取当前存储的状态,以防万一 isRunning 变量状态不一致
  223.             if (GM_getValue(STORAGE_KEY_RUNNING, false)) {
  224.                 stopLoop();
  225.             } else {
  226.                 startLoop();
  227.             }
  228.         });

  229.         document.body.appendChild(controlButton);
  230.         log("控制按钮已创建。");
  231.     }

  232.     // --- 脚本入口 ---
  233.     log("脚本加载。");
  234.     createControlButton(); // 创建按钮

  235.     // 检查是否应该在页面加载后自动启动
  236.     if (GM_getValue(STORAGE_KEY_RUNNING, false)) {
  237.         log("检测到上次运行时脚本处于激活状态,自动启动流程。");
  238.         startLoop();
  239.     } else {
  240.         log("脚本当前处于停止状态。请点击按钮启动。");
  241.     }

  242. })();
复制代码
爱生活,爱奶昔~
您需要登录后才可以回帖 登录 | 注册

本版积分规则

  • 关注公众号
  • 添加微信客服
© 2025 Naixi Networks 沪ICP备13020230号-1|沪公网安备 31010702007642号
关灯 在本版发帖
扫一扫添加微信客服
返回顶部
快速回复 返回顶部 返回列表