fetch-signup-code.js 3.6 KB

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