activation-utils.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 isSubmitButton = hasForm
  23. && (
  24. (tagName === 'button' && (!type || type === 'submit'))
  25. || (tagName === 'input' && type === 'submit')
  26. );
  27. if (isSubmitButton) {
  28. return { method: 'click' };
  29. }
  30. return { method: 'click' };
  31. }
  32. function isRecoverableStep9AuthFailure(statusText) {
  33. const text = String(statusText || '').replace(/\s+/g, ' ').trim();
  34. if (!text) {
  35. return false;
  36. }
  37. if (/oauth flow is not pending/i.test(text)) {
  38. return true;
  39. }
  40. return /(?:认证失败|回调 URL 提交失败):\s*/i.test(text);
  41. }
  42. return {
  43. getActivationStrategy,
  44. isRecoverableStep9AuthFailure,
  45. };
  46. });