Plua模式开发

This commit is contained in:
QLHazyCoder
2026-04-26 01:41:40 +08:00
parent 12e6225eba
commit 6ad866b962
25 changed files with 2173 additions and 207 deletions
+129
View File
@@ -0,0 +1,129 @@
(function attachAddressSources(root, factory) {
root.MultiPageAddressSources = factory();
})(typeof self !== 'undefined' ? self : globalThis, function createAddressSourcesModule() {
const COUNTRY_ALIASES = {
AU: ['au', 'aus', 'australia', '澳大利亚'],
DE: ['de', 'deu', 'germany', 'deutschland', '德国'],
FR: ['fr', 'fra', 'france', '法国'],
US: ['us', 'usa', 'united states', 'united states of america', 'america', '美国'],
};
const ADDRESS_SEEDS = {
AU: [
{
query: 'New South Wales',
suggestionIndex: 1,
fallback: {
address1: 'Thyne Reid Drive',
city: 'Thredbo',
region: 'New South Wales',
postalCode: '2625',
},
},
{
query: 'Sydney NSW',
suggestionIndex: 1,
fallback: {
address1: 'George Street',
city: 'Sydney',
region: 'New South Wales',
postalCode: '2000',
},
},
],
DE: [
{
query: 'Berlin Mitte',
suggestionIndex: 1,
fallback: {
address1: 'Unter den Linden',
city: 'Berlin',
region: 'Berlin',
postalCode: '10117',
},
},
{
query: 'Munich Altstadt',
suggestionIndex: 1,
fallback: {
address1: 'Marienplatz',
city: 'Munich',
region: 'Bavaria',
postalCode: '80331',
},
},
],
FR: [
{
query: 'Paris France',
suggestionIndex: 1,
fallback: {
address1: 'Rue de Rivoli',
city: 'Paris',
region: 'Ile-de-France',
postalCode: '75001',
},
},
{
query: 'Lyon France',
suggestionIndex: 1,
fallback: {
address1: 'Rue de la Republique',
city: 'Lyon',
region: 'Auvergne-Rhone-Alpes',
postalCode: '69002',
},
},
],
US: [
{
query: 'New York NY',
suggestionIndex: 1,
fallback: {
address1: 'Broadway',
city: 'New York',
region: 'New York',
postalCode: '10007',
},
},
],
};
function normalizeCountryCode(value = '') {
const normalized = String(value || '').trim().toLowerCase();
if (!normalized) {
return '';
}
for (const [code, aliases] of Object.entries(COUNTRY_ALIASES)) {
if (aliases.some((alias) => normalized === alias || normalized.includes(alias))) {
return code;
}
}
const compact = normalized.replace(/[^a-z]/g, '').toUpperCase();
return ADDRESS_SEEDS[compact] ? compact : '';
}
function getAddressSeedForCountry(countryValue = '', options = {}) {
const fallbackCountry = normalizeCountryCode(options.fallbackCountry || 'DE') || 'DE';
const countryCode = normalizeCountryCode(countryValue) || fallbackCountry;
const candidates = ADDRESS_SEEDS[countryCode] || ADDRESS_SEEDS[fallbackCountry] || [];
const seed = candidates[0] || null;
if (!seed) {
return null;
}
return {
countryCode,
query: seed.query,
suggestionIndex: Math.max(0, Math.floor(Number(seed.suggestionIndex) || 0)),
fallback: { ...(seed.fallback || {}) },
};
}
return {
ADDRESS_SEEDS,
getAddressSeedForCountry,
normalizeCountryCode,
};
});
+64 -6
View File
@@ -1,7 +1,7 @@
(function attachStepDefinitions(root, factory) {
root.MultiPageStepDefinitions = factory();
})(typeof self !== 'undefined' ? self : globalThis, function createStepDefinitionsModule() {
const STEP_DEFINITIONS = [
const NORMAL_STEP_DEFINITIONS = [
{ id: 1, order: 10, key: 'open-chatgpt', title: '打开 ChatGPT 官网' },
{ id: 2, order: 20, key: 'submit-signup-email', title: '注册并输入邮箱' },
{ id: 3, order: 30, key: 'fill-password', title: '填写密码并继续' },
@@ -14,19 +14,77 @@
{ id: 10, order: 100, key: 'platform-verify', title: '平台回调验证' },
];
function getSteps() {
return STEP_DEFINITIONS.map((step) => ({ ...step }));
const PLUS_STEP_DEFINITIONS = [
{ id: 1, order: 10, key: 'open-chatgpt', title: '打开 ChatGPT 官网' },
{ id: 2, order: 20, key: 'submit-signup-email', title: '注册并输入邮箱' },
{ id: 3, order: 30, key: 'fill-password', title: '填写密码并继续' },
{ id: 4, order: 40, key: 'fetch-signup-code', title: '获取注册验证码' },
{ id: 5, order: 50, key: 'fill-profile', title: '填写姓名和生日' },
{ id: 6, order: 60, key: 'plus-checkout-create', title: '创建 Plus Checkout' },
{ id: 7, order: 70, key: 'plus-checkout-billing', title: '填写账单并提交订阅' },
{ id: 8, order: 80, key: 'paypal-approve', title: 'PayPal 登录与授权' },
{ id: 9, order: 90, key: 'plus-checkout-return', title: '订阅回跳确认' },
{ id: 10, order: 100, key: 'oauth-login', title: '刷新 OAuth 并登录' },
{ id: 11, order: 110, key: 'confirm-oauth', title: '自动确认 OAuth' },
{ id: 12, order: 120, key: 'platform-verify', title: '平台回调验证' },
];
function isPlusModeEnabled(options = {}) {
return Boolean(options?.plusModeEnabled || options?.plusMode);
}
function getStepById(id) {
function getModeStepDefinitions(options = {}) {
return isPlusModeEnabled(options) ? PLUS_STEP_DEFINITIONS : NORMAL_STEP_DEFINITIONS;
}
function cloneSteps(steps = []) {
return steps.map((step) => ({ ...step }));
}
function getSteps(options = {}) {
return cloneSteps(getModeStepDefinitions(options));
}
function getAllSteps() {
const keyed = new Map();
for (const step of [...NORMAL_STEP_DEFINITIONS, ...PLUS_STEP_DEFINITIONS]) {
keyed.set(`${step.id}:${step.key}`, step);
}
return cloneSteps(Array.from(keyed.values()).sort((left, right) => {
const leftOrder = Number.isFinite(left.order) ? left.order : left.id;
const rightOrder = Number.isFinite(right.order) ? right.order : right.id;
if (leftOrder !== rightOrder) return leftOrder - rightOrder;
return left.id - right.id;
}));
}
function getStepIds(options = {}) {
return getModeStepDefinitions(options)
.map((step) => Number(step.id))
.filter(Number.isFinite)
.sort((left, right) => left - right);
}
function getLastStepId(options = {}) {
const ids = getStepIds(options);
return ids[ids.length - 1] || 0;
}
function getStepById(id, options = {}) {
const numericId = Number(id);
const match = STEP_DEFINITIONS.find((step) => step.id === numericId);
const match = getModeStepDefinitions(options).find((step) => step.id === numericId);
return match ? { ...match } : null;
}
return {
STEP_DEFINITIONS,
STEP_DEFINITIONS: NORMAL_STEP_DEFINITIONS,
NORMAL_STEP_DEFINITIONS,
PLUS_STEP_DEFINITIONS,
getAllSteps,
getLastStepId,
getStepById,
getStepIds,
getSteps,
isPlusModeEnabled,
};
});