fetch-signup-code.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. (function attachBackgroundStep4(root, factory) {
  2. root.MultiPageBackgroundStep4 = factory();
  3. })(typeof self !== 'undefined' ? self : globalThis, function createBackgroundStep4Module() {
  4. function createStep4Executor(deps = {}) {
  5. const {
  6. addLog,
  7. chrome,
  8. completeStepFromBackground,
  9. confirmCustomVerificationStepBypass,
  10. getMailConfig,
  11. getTabId,
  12. HOTMAIL_PROVIDER,
  13. isTabAlive,
  14. LUCKMAIL_PROVIDER,
  15. CLOUDFLARE_TEMP_EMAIL_PROVIDER,
  16. resolveVerificationStep,
  17. reuseOrCreateTab,
  18. sendToContentScriptResilient,
  19. shouldUseCustomRegistrationEmail,
  20. STANDARD_MAIL_VERIFICATION_RESEND_INTERVAL_MS,
  21. throwIfStopped,
  22. } = deps;
  23. async function executeStep4(state) {
  24. const mail = getMailConfig(state);
  25. if (mail.error) throw new Error(mail.error);
  26. const stepStartedAt = Date.now();
  27. const signupTabId = await getTabId('signup-page');
  28. if (!signupTabId) {
  29. throw new Error('认证页面标签页已关闭,无法继续步骤 4。');
  30. }
  31. await chrome.tabs.update(signupTabId, { active: true });
  32. throwIfStopped();
  33. await addLog('步骤 4:正在确认注册验证码页面是否就绪,必要时自动恢复密码页超时报错...');
  34. const prepareResult = await sendToContentScriptResilient(
  35. 'signup-page',
  36. {
  37. type: 'PREPARE_SIGNUP_VERIFICATION',
  38. step: 4,
  39. source: 'background',
  40. payload: { password: state.password || state.customPassword || '' },
  41. },
  42. {
  43. timeoutMs: 30000,
  44. retryDelayMs: 700,
  45. logMessage: '步骤 4:认证页正在切换,等待页面重新就绪后继续检测...',
  46. }
  47. );
  48. if (prepareResult && prepareResult.error) {
  49. throw new Error(prepareResult.error);
  50. }
  51. if (prepareResult?.alreadyVerified) {
  52. await completeStepFromBackground(4, {});
  53. return;
  54. }
  55. if (shouldUseCustomRegistrationEmail(state)) {
  56. await confirmCustomVerificationStepBypass(4);
  57. return;
  58. }
  59. throwIfStopped();
  60. if (mail.provider === HOTMAIL_PROVIDER || mail.provider === LUCKMAIL_PROVIDER || mail.provider === CLOUDFLARE_TEMP_EMAIL_PROVIDER) {
  61. await addLog(`步骤 4:正在通过 ${mail.label} 轮询验证码...`);
  62. } else {
  63. await addLog(`步骤 4:正在打开${mail.label}...`);
  64. const alive = await isTabAlive(mail.source);
  65. if (alive) {
  66. if (mail.navigateOnReuse) {
  67. await reuseOrCreateTab(mail.source, mail.url, {
  68. inject: mail.inject,
  69. injectSource: mail.injectSource,
  70. });
  71. } else {
  72. const tabId = await getTabId(mail.source);
  73. await chrome.tabs.update(tabId, { active: true });
  74. }
  75. } else {
  76. await reuseOrCreateTab(mail.source, mail.url, {
  77. inject: mail.inject,
  78. injectSource: mail.injectSource,
  79. });
  80. }
  81. }
  82. await resolveVerificationStep(4, state, mail, {
  83. filterAfterTimestamp: mail.provider === HOTMAIL_PROVIDER ? undefined : stepStartedAt,
  84. requestFreshCodeFirst: mail.provider === HOTMAIL_PROVIDER ? false : true,
  85. resendIntervalMs: mail.provider === HOTMAIL_PROVIDER ? 0 : STANDARD_MAIL_VERIFICATION_RESEND_INTERVAL_MS,
  86. });
  87. }
  88. return { executeStep4 };
  89. }
  90. return { createStep4Executor };
  91. });