activation-utils.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. return /认证失败:\s*/i.test(String(statusText || '').trim());
  35. }
  36. return {
  37. getActivationStrategy,
  38. isRecoverableStep9AuthFailure,
  39. };
  40. });