activation-utils.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. (function activationUtilsModule(root, factory) {
  2. if (typeof module !== 'undefined' && module.exports) {
  3. module.exports = factory();
  4. return;
  5. }
  6. root.MultiPageActivationUtils = factory();
  7. })(typeof self !== 'undefined' ? self : globalThis, function createActivationUtils() {
  8. function normalizeTagName(tagName) {
  9. return String(tagName || '').trim().toLowerCase();
  10. }
  11. function normalizeType(type) {
  12. return String(type || '').trim().toLowerCase();
  13. }
  14. function normalizePathname(pathname) {
  15. return String(pathname || '').trim().toLowerCase();
  16. }
  17. function getActivationStrategy(target = {}) {
  18. const tagName = normalizeTagName(target.tagName);
  19. const type = normalizeType(target.type);
  20. const pathname = normalizePathname(target.pathname);
  21. const hasForm = Boolean(target.hasForm);
  22. const isEmailVerificationRoute = /\/email-verification(?:[/?#]|$)/i.test(pathname);
  23. const isSubmitButton = hasForm
  24. && (
  25. (tagName === 'button' && (!type || type === 'submit'))
  26. || (tagName === 'input' && type === 'submit')
  27. );
  28. if (isSubmitButton && isEmailVerificationRoute) {
  29. return { method: 'requestSubmit' };
  30. }
  31. return { method: 'click' };
  32. }
  33. function isRecoverableStep9AuthFailure(statusText) {
  34. const text = String(statusText || '').replace(/\s+/g, ' ').trim();
  35. if (!text) {
  36. return false;
  37. }
  38. if (/oauth flow is not pending/i.test(text)) {
  39. return true;
  40. }
  41. return /(?:认证失败|回调 URL 提交失败):\s*/i.test(text);
  42. }
  43. return {
  44. getActivationStrategy,
  45. isRecoverableStep9AuthFailure,
  46. };
  47. });