Paypal增加轻量级号池
This commit is contained in:
@@ -0,0 +1,233 @@
|
||||
(function attachSidepanelFormDialog(globalScope) {
|
||||
function createFormDialog(context = {}) {
|
||||
const {
|
||||
overlay = null,
|
||||
titleNode = null,
|
||||
closeButton = null,
|
||||
messageNode = null,
|
||||
alertNode = null,
|
||||
fieldsContainer = null,
|
||||
cancelButton = null,
|
||||
confirmButton = null,
|
||||
documentRef = globalScope.document,
|
||||
} = context;
|
||||
|
||||
let resolver = null;
|
||||
let currentConfig = null;
|
||||
let currentInputs = [];
|
||||
|
||||
function setHidden(node, hidden) {
|
||||
if (!node) return;
|
||||
node.hidden = Boolean(hidden);
|
||||
}
|
||||
|
||||
function resetAlert() {
|
||||
if (!alertNode) return;
|
||||
alertNode.textContent = '';
|
||||
alertNode.className = 'modal-alert modal-form-alert';
|
||||
alertNode.hidden = true;
|
||||
}
|
||||
|
||||
function setAlert(message = '', tone = 'danger') {
|
||||
if (!alertNode) return;
|
||||
const text = String(message || '').trim();
|
||||
if (!text) {
|
||||
resetAlert();
|
||||
return;
|
||||
}
|
||||
alertNode.textContent = text;
|
||||
alertNode.className = `modal-alert modal-form-alert${tone === 'danger' ? ' is-danger' : ''}`;
|
||||
alertNode.hidden = false;
|
||||
}
|
||||
|
||||
function close(result = null) {
|
||||
if (resolver) {
|
||||
resolver(result);
|
||||
resolver = null;
|
||||
}
|
||||
currentConfig = null;
|
||||
currentInputs = [];
|
||||
resetAlert();
|
||||
if (fieldsContainer) {
|
||||
fieldsContainer.innerHTML = '';
|
||||
}
|
||||
if (overlay) {
|
||||
overlay.hidden = true;
|
||||
}
|
||||
}
|
||||
|
||||
function buildFieldNode(field, values) {
|
||||
const wrapper = documentRef.createElement('div');
|
||||
wrapper.className = 'modal-form-row';
|
||||
|
||||
const label = documentRef.createElement('label');
|
||||
label.className = 'modal-form-label';
|
||||
label.textContent = String(field.label || field.key || '').trim();
|
||||
wrapper.appendChild(label);
|
||||
|
||||
let input = null;
|
||||
if (field.type === 'textarea') {
|
||||
input = documentRef.createElement('textarea');
|
||||
input.className = 'data-textarea';
|
||||
} else if (field.type === 'select') {
|
||||
input = documentRef.createElement('select');
|
||||
input.className = 'data-select';
|
||||
const options = Array.isArray(field.options) ? field.options : [];
|
||||
options.forEach((option) => {
|
||||
const optionNode = documentRef.createElement('option');
|
||||
optionNode.value = String(option?.value || '');
|
||||
optionNode.textContent = String(option?.label || option?.value || '');
|
||||
input.appendChild(optionNode);
|
||||
});
|
||||
} else {
|
||||
input = documentRef.createElement('input');
|
||||
input.type = field.type === 'password' ? 'password' : 'text';
|
||||
input.className = 'data-input';
|
||||
}
|
||||
|
||||
const normalizedValue = Object.prototype.hasOwnProperty.call(values, field.key)
|
||||
? values[field.key]
|
||||
: field.value;
|
||||
if (normalizedValue !== undefined && normalizedValue !== null) {
|
||||
input.value = String(normalizedValue);
|
||||
}
|
||||
if (field.placeholder) {
|
||||
input.placeholder = String(field.placeholder);
|
||||
}
|
||||
if (field.autocomplete) {
|
||||
input.autocomplete = String(field.autocomplete);
|
||||
}
|
||||
if (field.inputMode) {
|
||||
input.inputMode = String(field.inputMode);
|
||||
}
|
||||
if (field.rows && field.type === 'textarea') {
|
||||
input.rows = Number(field.rows) || 3;
|
||||
}
|
||||
input.dataset.fieldKey = String(field.key || '');
|
||||
label.htmlFor = field.key;
|
||||
input.id = field.key;
|
||||
wrapper.appendChild(input);
|
||||
|
||||
if (field.type !== 'textarea') {
|
||||
input.addEventListener('keydown', (event) => {
|
||||
if (event.key !== 'Enter') {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
void handleConfirm();
|
||||
});
|
||||
}
|
||||
|
||||
currentInputs.push({ field, input });
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
function collectValues() {
|
||||
return currentInputs.reduce((result, item) => {
|
||||
result[item.field.key] = item.input.value;
|
||||
return result;
|
||||
}, {});
|
||||
}
|
||||
|
||||
async function handleConfirm() {
|
||||
if (!currentConfig) {
|
||||
close(null);
|
||||
return;
|
||||
}
|
||||
|
||||
const values = collectValues();
|
||||
resetAlert();
|
||||
|
||||
for (const item of currentInputs) {
|
||||
const { field, input } = item;
|
||||
const rawValue = values[field.key];
|
||||
const textValue = String(rawValue || '').trim();
|
||||
if (field.required && !textValue) {
|
||||
setAlert(field.requiredMessage || `${field.label || field.key}不能为空。`);
|
||||
input.focus?.();
|
||||
return;
|
||||
}
|
||||
if (typeof field.validate === 'function') {
|
||||
const validationMessage = await field.validate(rawValue, values);
|
||||
if (validationMessage) {
|
||||
setAlert(validationMessage);
|
||||
input.focus?.();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
close(values);
|
||||
}
|
||||
|
||||
function bindEvents() {
|
||||
overlay?.addEventListener('click', (event) => {
|
||||
if (event.target === overlay) {
|
||||
close(null);
|
||||
}
|
||||
});
|
||||
closeButton?.addEventListener('click', () => close(null));
|
||||
cancelButton?.addEventListener('click', () => close(null));
|
||||
confirmButton?.addEventListener('click', () => {
|
||||
void handleConfirm();
|
||||
});
|
||||
}
|
||||
|
||||
async function open(config = {}) {
|
||||
if (!overlay || !titleNode || !fieldsContainer || !confirmButton) {
|
||||
return null;
|
||||
}
|
||||
if (resolver) {
|
||||
close(null);
|
||||
}
|
||||
|
||||
currentConfig = config || {};
|
||||
currentInputs = [];
|
||||
titleNode.textContent = String(currentConfig.title || '填写表单');
|
||||
if (messageNode) {
|
||||
const message = String(currentConfig.message || '').trim();
|
||||
messageNode.textContent = message;
|
||||
setHidden(messageNode, !message);
|
||||
}
|
||||
resetAlert();
|
||||
if (currentConfig.alert?.text) {
|
||||
setAlert(currentConfig.alert.text, currentConfig.alert.tone || 'danger');
|
||||
}
|
||||
|
||||
confirmButton.textContent = String(currentConfig.confirmLabel || '确认');
|
||||
confirmButton.className = `btn ${currentConfig.confirmVariant || 'btn-primary'} btn-sm`;
|
||||
fieldsContainer.innerHTML = '';
|
||||
|
||||
const initialValues = currentConfig.initialValues && typeof currentConfig.initialValues === 'object'
|
||||
? currentConfig.initialValues
|
||||
: {};
|
||||
const fields = Array.isArray(currentConfig.fields) ? currentConfig.fields : [];
|
||||
fields.forEach((field) => {
|
||||
fieldsContainer.appendChild(buildFieldNode(field, initialValues));
|
||||
});
|
||||
|
||||
overlay.hidden = false;
|
||||
const firstInput = currentInputs[0]?.input || null;
|
||||
if (firstInput && typeof globalScope.requestAnimationFrame === 'function') {
|
||||
globalScope.requestAnimationFrame(() => firstInput.focus?.());
|
||||
} else {
|
||||
firstInput?.focus?.();
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
resolver = resolve;
|
||||
});
|
||||
}
|
||||
|
||||
bindEvents();
|
||||
|
||||
return {
|
||||
close,
|
||||
open,
|
||||
};
|
||||
}
|
||||
|
||||
globalScope.SidepanelFormDialog = {
|
||||
createFormDialog,
|
||||
};
|
||||
})(window);
|
||||
@@ -0,0 +1,191 @@
|
||||
(function attachSidepanelPayPalManager(globalScope) {
|
||||
function createPayPalManager(context = {}) {
|
||||
const {
|
||||
state,
|
||||
dom,
|
||||
helpers,
|
||||
runtime,
|
||||
paypalUtils = {},
|
||||
} = context;
|
||||
|
||||
let actionInFlight = false;
|
||||
|
||||
function getPayPalAccounts(currentState = state.getLatestState()) {
|
||||
return helpers.getPayPalAccounts(currentState);
|
||||
}
|
||||
|
||||
function getCurrentPayPalAccountId(currentState = state.getLatestState()) {
|
||||
return String(currentState?.currentPayPalAccountId || '').trim();
|
||||
}
|
||||
|
||||
function buildSelectOptions(accounts = []) {
|
||||
if (!accounts.length) {
|
||||
return '<option value="">请先添加 PayPal 账号</option>';
|
||||
}
|
||||
return accounts.map((account) => (
|
||||
`<option value="${helpers.escapeHtml(account.id)}">${helpers.escapeHtml(account.email || '(未命名账号)')}</option>`
|
||||
)).join('');
|
||||
}
|
||||
|
||||
function applyPayPalAccountMutation(account) {
|
||||
if (!account?.id) return;
|
||||
const latestState = state.getLatestState();
|
||||
const nextAccounts = typeof paypalUtils.upsertPayPalAccountInList === 'function'
|
||||
? paypalUtils.upsertPayPalAccountInList(getPayPalAccounts(latestState), account)
|
||||
: [...getPayPalAccounts(latestState), account];
|
||||
state.syncLatestState({ paypalAccounts: nextAccounts });
|
||||
renderPayPalAccounts();
|
||||
}
|
||||
|
||||
function renderPayPalAccounts() {
|
||||
if (!dom.selectPayPalAccount) return;
|
||||
|
||||
const latestState = state.getLatestState();
|
||||
const accounts = getPayPalAccounts(latestState);
|
||||
const currentId = getCurrentPayPalAccountId(latestState);
|
||||
|
||||
dom.selectPayPalAccount.innerHTML = buildSelectOptions(accounts);
|
||||
dom.selectPayPalAccount.disabled = accounts.length === 0;
|
||||
dom.selectPayPalAccount.value = accounts.some((account) => account.id === currentId) ? currentId : '';
|
||||
}
|
||||
|
||||
async function syncSelectedPayPalAccount(options = {}) {
|
||||
const { silent = false } = options;
|
||||
const accountId = String(dom.selectPayPalAccount?.value || '').trim();
|
||||
if (!accountId) {
|
||||
state.syncLatestState({
|
||||
currentPayPalAccountId: null,
|
||||
paypalEmail: '',
|
||||
paypalPassword: '',
|
||||
});
|
||||
renderPayPalAccounts();
|
||||
return null;
|
||||
}
|
||||
|
||||
const response = await runtime.sendMessage({
|
||||
type: 'SELECT_PAYPAL_ACCOUNT',
|
||||
source: 'sidepanel',
|
||||
payload: { accountId },
|
||||
});
|
||||
if (response?.error) {
|
||||
throw new Error(response.error);
|
||||
}
|
||||
|
||||
state.syncLatestState({
|
||||
currentPayPalAccountId: response.account?.id || accountId,
|
||||
paypalEmail: String(response.account?.email || '').trim(),
|
||||
paypalPassword: String(response.account?.password || ''),
|
||||
});
|
||||
renderPayPalAccounts();
|
||||
if (!silent) {
|
||||
helpers.showToast(`已切换当前 PayPal 账号为 ${response.account?.email || accountId}`, 'success', 1800);
|
||||
}
|
||||
return response.account || null;
|
||||
}
|
||||
|
||||
async function openPayPalAccountDialog() {
|
||||
if (typeof helpers.openFormDialog !== 'function') {
|
||||
throw new Error('表单弹窗能力未加载,请刷新扩展后重试。');
|
||||
}
|
||||
return helpers.openFormDialog({
|
||||
title: '添加 PayPal 账号',
|
||||
confirmLabel: '保存账号',
|
||||
confirmVariant: 'btn-primary',
|
||||
fields: [
|
||||
{
|
||||
key: 'email',
|
||||
label: 'PayPal 账号',
|
||||
type: 'text',
|
||||
placeholder: '请输入 PayPal 登录邮箱',
|
||||
autocomplete: 'username',
|
||||
required: true,
|
||||
requiredMessage: '请先填写 PayPal 账号。',
|
||||
validate: (value) => {
|
||||
const normalized = String(value || '').trim();
|
||||
if (!normalized.includes('@')) {
|
||||
return 'PayPal 账号需填写邮箱格式。';
|
||||
}
|
||||
return '';
|
||||
},
|
||||
},
|
||||
{
|
||||
key: 'password',
|
||||
label: 'PayPal 密码',
|
||||
type: 'password',
|
||||
placeholder: '请输入 PayPal 登录密码',
|
||||
autocomplete: 'current-password',
|
||||
required: true,
|
||||
requiredMessage: '请先填写 PayPal 密码。',
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
async function handleAddPayPalAccount() {
|
||||
if (actionInFlight) return;
|
||||
|
||||
const formValues = await openPayPalAccountDialog();
|
||||
if (!formValues) {
|
||||
return;
|
||||
}
|
||||
|
||||
actionInFlight = true;
|
||||
if (dom.btnAddPayPalAccount) {
|
||||
dom.btnAddPayPalAccount.disabled = true;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await runtime.sendMessage({
|
||||
type: 'UPSERT_PAYPAL_ACCOUNT',
|
||||
source: 'sidepanel',
|
||||
payload: {
|
||||
email: String(formValues.email || '').trim(),
|
||||
password: String(formValues.password || ''),
|
||||
},
|
||||
});
|
||||
if (response?.error) {
|
||||
throw new Error(response.error);
|
||||
}
|
||||
|
||||
applyPayPalAccountMutation(response.account);
|
||||
if (response.account?.id) {
|
||||
state.syncLatestState({ currentPayPalAccountId: response.account.id });
|
||||
renderPayPalAccounts();
|
||||
dom.selectPayPalAccount.value = response.account.id;
|
||||
await syncSelectedPayPalAccount({ silent: true });
|
||||
}
|
||||
helpers.showToast(`已保存 PayPal 账号 ${response.account?.email || ''}`, 'success', 2200);
|
||||
} catch (error) {
|
||||
helpers.showToast(`保存 PayPal 账号失败:${error.message}`, 'error');
|
||||
throw error;
|
||||
} finally {
|
||||
actionInFlight = false;
|
||||
if (dom.btnAddPayPalAccount) {
|
||||
dom.btnAddPayPalAccount.disabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function bindPayPalEvents() {
|
||||
dom.btnAddPayPalAccount?.addEventListener('click', () => {
|
||||
void handleAddPayPalAccount();
|
||||
});
|
||||
dom.selectPayPalAccount?.addEventListener('change', () => {
|
||||
void syncSelectedPayPalAccount().catch((error) => {
|
||||
helpers.showToast(error.message, 'error');
|
||||
renderPayPalAccounts();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
bindPayPalEvents,
|
||||
renderPayPalAccounts,
|
||||
syncSelectedPayPalAccount,
|
||||
};
|
||||
}
|
||||
|
||||
globalScope.SidepanelPayPalManager = {
|
||||
createPayPalManager,
|
||||
};
|
||||
})(window);
|
||||
@@ -2722,6 +2722,36 @@ header {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.modal-form-fields {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.modal-form-row {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.modal-form-label {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.modal-form-row .data-input,
|
||||
.modal-form-row .data-select,
|
||||
.modal-form-row .data-textarea {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.modal-form-alert {
|
||||
margin-top: -4px;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.modal-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
|
||||
@@ -383,13 +383,14 @@
|
||||
<span class="setting-caption">PayPal 订阅链路</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="data-row" id="row-paypal-email" style="display:none;">
|
||||
<div class="data-row" id="row-paypal-account" style="display:none;">
|
||||
<span class="data-label">PayPal 账号</span>
|
||||
<input type="text" id="input-paypal-email" class="data-input" placeholder="请输入 PayPal 登录邮箱" />
|
||||
</div>
|
||||
<div class="data-row" id="row-paypal-password" style="display:none;">
|
||||
<span class="data-label">PayPal 密码</span>
|
||||
<input type="password" id="input-paypal-password" class="data-input" placeholder="请输入 PayPal 登录密码" />
|
||||
<div class="data-inline">
|
||||
<select id="select-paypal-account" class="data-select">
|
||||
<option value="">请先添加 PayPal 账号</option>
|
||||
</select>
|
||||
<button id="btn-add-paypal-account" class="btn btn-outline btn-sm data-inline-btn" type="button">添加</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="data-row">
|
||||
<span class="data-label">邮箱服务</span>
|
||||
@@ -986,6 +987,22 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="shared-form-modal" class="modal-overlay" hidden>
|
||||
<div class="modal-card modal-card-form">
|
||||
<div class="modal-header">
|
||||
<span id="shared-form-modal-title" class="modal-title">添加账号</span>
|
||||
<button id="btn-shared-form-modal-close" class="modal-close" type="button" aria-label="关闭">×</button>
|
||||
</div>
|
||||
<p id="shared-form-modal-message" class="modal-message" hidden></p>
|
||||
<p id="shared-form-modal-alert" class="modal-alert" hidden></p>
|
||||
<div id="shared-form-modal-fields" class="modal-form-fields"></div>
|
||||
<div class="modal-actions">
|
||||
<button id="btn-shared-form-modal-cancel" class="btn btn-ghost btn-sm" type="button">取消</button>
|
||||
<button id="btn-shared-form-modal-confirm" class="btn btn-primary btn-sm" type="button">确认</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="auto-start-modal" class="modal-overlay" hidden>
|
||||
<div class="modal-card">
|
||||
<div class="modal-header">
|
||||
@@ -1012,6 +1029,7 @@
|
||||
<input id="input-import-settings-file" type="file" accept=".json,application/json" hidden />
|
||||
<script src="../managed-alias-utils.js"></script>
|
||||
<script src="../mail2925-utils.js"></script>
|
||||
<script src="../paypal-utils.js"></script>
|
||||
<script src="../icloud-utils.js"></script>
|
||||
<script src="../mail-provider-utils.js"></script>
|
||||
<script src="../hotmail-utils.js"></script>
|
||||
@@ -1020,8 +1038,10 @@
|
||||
<script src="update-service.js"></script>
|
||||
<script src="contribution-content-update-service.js"></script>
|
||||
<script src="account-pool-ui.js"></script>
|
||||
<script src="form-dialog.js"></script>
|
||||
<script src="hotmail-manager.js"></script>
|
||||
<script src="mail-2925-manager.js"></script>
|
||||
<script src="paypal-manager.js"></script>
|
||||
<script src="icloud-manager.js"></script>
|
||||
<script src="luckmail-manager.js"></script>
|
||||
<script src="ip-proxy-provider-711proxy.js"></script>
|
||||
|
||||
+83
-28
@@ -157,10 +157,9 @@ const inputCodex2ApiAdminKey = document.getElementById('input-codex2api-admin-ke
|
||||
const rowCustomPassword = document.getElementById('row-custom-password');
|
||||
const rowPlusMode = document.getElementById('row-plus-mode');
|
||||
const inputPlusModeEnabled = document.getElementById('input-plus-mode-enabled');
|
||||
const rowPaypalEmail = document.getElementById('row-paypal-email');
|
||||
const inputPaypalEmail = document.getElementById('input-paypal-email');
|
||||
const rowPaypalPassword = document.getElementById('row-paypal-password');
|
||||
const inputPaypalPassword = document.getElementById('input-paypal-password');
|
||||
const rowPayPalAccount = document.getElementById('row-paypal-account');
|
||||
const selectPayPalAccount = document.getElementById('select-paypal-account');
|
||||
const btnAddPayPalAccount = document.getElementById('btn-add-paypal-account');
|
||||
const selectMailProvider = document.getElementById('select-mail-provider');
|
||||
const btnMailLogin = document.getElementById('btn-mail-login');
|
||||
const rowCustomMailProviderPool = document.getElementById('row-custom-mail-provider-pool');
|
||||
@@ -299,6 +298,14 @@ const displayHeroSmsPlatform = document.getElementById('display-hero-sms-platfor
|
||||
const rowAccountRunHistoryHelperBaseUrl = document.getElementById('row-account-run-history-helper-base-url');
|
||||
const inputAccountRunHistoryHelperBaseUrl = document.getElementById('input-account-run-history-helper-base-url');
|
||||
const autoStartModal = document.getElementById('auto-start-modal');
|
||||
const sharedFormModal = document.getElementById('shared-form-modal');
|
||||
const sharedFormModalTitle = document.getElementById('shared-form-modal-title');
|
||||
const btnSharedFormModalClose = document.getElementById('btn-shared-form-modal-close');
|
||||
const sharedFormModalMessage = document.getElementById('shared-form-modal-message');
|
||||
const sharedFormModalAlert = document.getElementById('shared-form-modal-alert');
|
||||
const sharedFormModalFields = document.getElementById('shared-form-modal-fields');
|
||||
const btnSharedFormModalCancel = document.getElementById('btn-shared-form-modal-cancel');
|
||||
const btnSharedFormModalConfirm = document.getElementById('btn-shared-form-modal-confirm');
|
||||
const autoStartTitle = autoStartModal?.querySelector('.modal-title');
|
||||
const autoStartMessage = document.getElementById('auto-start-message');
|
||||
const autoStartAlert = document.getElementById('auto-start-alert');
|
||||
@@ -661,6 +668,7 @@ const upsertHotmailAccountInList = window.HotmailUtils?.upsertHotmailAccountInLi
|
||||
const filterHotmailAccountsByUsage = window.HotmailUtils?.filterHotmailAccountsByUsage;
|
||||
const getHotmailBulkActionLabel = window.HotmailUtils?.getHotmailBulkActionLabel;
|
||||
const getHotmailListToggleLabel = window.HotmailUtils?.getHotmailListToggleLabel;
|
||||
const upsertPayPalAccountInList = window.PayPalUtils?.upsertPayPalAccountInList;
|
||||
const normalizeLuckmailTimestampValue = window.LuckMailUtils?.normalizeTimestamp
|
||||
|| ((value) => {
|
||||
const timestamp = Date.parse(String(value || ''));
|
||||
@@ -668,6 +676,16 @@ const normalizeLuckmailTimestampValue = window.LuckMailUtils?.normalizeTimestamp
|
||||
});
|
||||
const sidepanelUpdateService = window.SidepanelUpdateService;
|
||||
const contributionContentService = window.SidepanelContributionContentService;
|
||||
const sharedFormDialog = window.SidepanelFormDialog?.createFormDialog?.({
|
||||
overlay: sharedFormModal,
|
||||
titleNode: sharedFormModalTitle,
|
||||
closeButton: btnSharedFormModalClose,
|
||||
messageNode: sharedFormModalMessage,
|
||||
alertNode: sharedFormModalAlert,
|
||||
fieldsContainer: sharedFormModalFields,
|
||||
cancelButton: btnSharedFormModalCancel,
|
||||
confirmButton: btnSharedFormModalConfirm,
|
||||
});
|
||||
const DEFAULT_LUCKMAIL_PRESERVE_TAG_NAME = window.LuckMailUtils?.DEFAULT_LUCKMAIL_PRESERVE_TAG_NAME || '保留';
|
||||
const normalizeIcloudHost = window.IcloudUtils?.normalizeIcloudHost
|
||||
|| ((value) => {
|
||||
@@ -793,6 +811,7 @@ function parseGmailBaseEmail(rawValue = '') {
|
||||
const value = String(rawValue || '').trim().toLowerCase();
|
||||
const match = value.match(/^([^@\s+]+)@((?:gmail|googlemail)\.com)$/i);
|
||||
if (!match) return null;
|
||||
|
||||
return {
|
||||
localPart: match[1],
|
||||
domain: match[2].toLowerCase(),
|
||||
@@ -2206,6 +2225,12 @@ function collectSettingsPayload() {
|
||||
id: typeof DEFAULT_HERO_SMS_COUNTRY_ID !== 'undefined' ? DEFAULT_HERO_SMS_COUNTRY_ID : 52,
|
||||
label: typeof DEFAULT_HERO_SMS_COUNTRY_LABEL !== 'undefined' ? DEFAULT_HERO_SMS_COUNTRY_LABEL : 'Thailand',
|
||||
};
|
||||
const payPalAccounts = typeof getPayPalAccounts === 'function'
|
||||
? getPayPalAccounts(latestState)
|
||||
: (Array.isArray(latestState?.paypalAccounts) ? latestState.paypalAccounts : []);
|
||||
const currentPayPalAccount = typeof getCurrentPayPalAccount === 'function'
|
||||
? getCurrentPayPalAccount(latestState)
|
||||
: payPalAccounts.find((account) => account?.id === String(latestState?.currentPayPalAccountId || '').trim()) || null;
|
||||
return {
|
||||
...(contributionModeEnabled ? {} : {
|
||||
panelMode: selectPanelMode.value,
|
||||
@@ -2238,12 +2263,10 @@ function collectSettingsPayload() {
|
||||
plusModeEnabled: typeof inputPlusModeEnabled !== 'undefined' && inputPlusModeEnabled
|
||||
? Boolean(inputPlusModeEnabled.checked)
|
||||
: Boolean(latestState?.plusModeEnabled),
|
||||
paypalEmail: typeof inputPaypalEmail !== 'undefined' && inputPaypalEmail
|
||||
? inputPaypalEmail.value.trim()
|
||||
: String(latestState?.paypalEmail || ''),
|
||||
paypalPassword: typeof inputPaypalPassword !== 'undefined' && inputPaypalPassword
|
||||
? inputPaypalPassword.value
|
||||
: String(latestState?.paypalPassword || ''),
|
||||
paypalEmail: String(currentPayPalAccount?.email || latestState?.paypalEmail || '').trim(),
|
||||
paypalPassword: String(currentPayPalAccount?.password || latestState?.paypalPassword || ''),
|
||||
currentPayPalAccountId: String(latestState?.currentPayPalAccountId || '').trim(),
|
||||
paypalAccounts: payPalAccounts,
|
||||
...(contributionModeEnabled ? {} : {
|
||||
customPassword: inputPassword.value,
|
||||
}),
|
||||
@@ -2485,8 +2508,7 @@ function updatePlusModeUI() {
|
||||
? Boolean(inputPlusModeEnabled.checked)
|
||||
: false;
|
||||
[
|
||||
typeof rowPaypalEmail !== 'undefined' ? rowPaypalEmail : null,
|
||||
typeof rowPaypalPassword !== 'undefined' ? rowPaypalPassword : null,
|
||||
typeof rowPayPalAccount !== 'undefined' ? rowPayPalAccount : null,
|
||||
].forEach((row) => {
|
||||
if (!row) {
|
||||
return;
|
||||
@@ -2793,12 +2815,6 @@ function applySettingsState(state) {
|
||||
if (typeof inputPlusModeEnabled !== 'undefined' && inputPlusModeEnabled) {
|
||||
inputPlusModeEnabled.checked = Boolean(state?.plusModeEnabled);
|
||||
}
|
||||
if (typeof inputPaypalEmail !== 'undefined' && inputPaypalEmail) {
|
||||
inputPaypalEmail.value = state?.paypalEmail || '';
|
||||
}
|
||||
if (typeof inputPaypalPassword !== 'undefined' && inputPaypalPassword) {
|
||||
inputPaypalPassword.value = state?.paypalPassword || '';
|
||||
}
|
||||
inputVpsUrl.value = state?.vpsUrl || '';
|
||||
inputVpsPassword.value = state?.vpsPassword || '';
|
||||
setLocalCpaStep9Mode(state?.localCpaStep9Mode);
|
||||
@@ -3000,6 +3016,9 @@ function applySettingsState(state) {
|
||||
updateFallbackThreadIntervalInputState();
|
||||
updateAccountRunHistorySettingsUI();
|
||||
updatePhoneVerificationSettingsUI();
|
||||
if (typeof renderPayPalAccounts === 'function') {
|
||||
renderPayPalAccounts();
|
||||
}
|
||||
if (typeof updatePlusModeUI === 'function') {
|
||||
updatePlusModeUI();
|
||||
}
|
||||
@@ -3664,6 +3683,15 @@ function getCurrentMail2925Email(state = latestState) {
|
||||
return String(getCurrentMail2925Account(state)?.email || '').trim();
|
||||
}
|
||||
|
||||
function getPayPalAccounts(state = latestState) {
|
||||
return Array.isArray(state?.paypalAccounts) ? state.paypalAccounts : [];
|
||||
}
|
||||
|
||||
function getCurrentPayPalAccount(state = latestState) {
|
||||
const currentId = String(state?.currentPayPalAccountId || '').trim();
|
||||
return getPayPalAccounts(state).find((account) => account.id === currentId) || null;
|
||||
}
|
||||
|
||||
function syncMail2925BaseEmailFromCurrentAccount(state = latestState, options = {}) {
|
||||
const { persist = false } = options;
|
||||
if (!isMail2925AccountPoolEnabled(state)) {
|
||||
@@ -4564,6 +4592,39 @@ const bindHotmailEvents = hotmailManager?.bindHotmailEvents
|
||||
|| (() => { });
|
||||
bindHotmailEvents();
|
||||
|
||||
const payPalManager = window.SidepanelPayPalManager?.createPayPalManager({
|
||||
state: {
|
||||
getLatestState: () => latestState,
|
||||
syncLatestState,
|
||||
},
|
||||
dom: {
|
||||
btnAddPayPalAccount,
|
||||
selectPayPalAccount,
|
||||
},
|
||||
helpers: {
|
||||
escapeHtml,
|
||||
getPayPalAccounts,
|
||||
openFormDialog: (options) => {
|
||||
if (!sharedFormDialog?.open) {
|
||||
throw new Error('表单弹窗能力未加载,请刷新扩展后重试。');
|
||||
}
|
||||
return sharedFormDialog.open(options);
|
||||
},
|
||||
showToast,
|
||||
},
|
||||
runtime: {
|
||||
sendMessage: (message) => chrome.runtime.sendMessage(message),
|
||||
},
|
||||
paypalUtils: {
|
||||
upsertPayPalAccountInList,
|
||||
},
|
||||
});
|
||||
const renderPayPalAccounts = payPalManager?.renderPayPalAccounts
|
||||
|| (() => { });
|
||||
const bindPayPalEvents = payPalManager?.bindPayPalEvents
|
||||
|| (() => { });
|
||||
bindPayPalEvents();
|
||||
|
||||
const mail2925Manager = window.SidepanelMail2925Manager?.createMail2925Manager({
|
||||
state: {
|
||||
getLatestState: () => latestState,
|
||||
@@ -5525,16 +5586,6 @@ inputPlusModeEnabled?.addEventListener('change', () => {
|
||||
saveSettings({ silent: true }).catch(() => { });
|
||||
});
|
||||
|
||||
[inputPaypalEmail, inputPaypalPassword].forEach((input) => {
|
||||
input?.addEventListener('input', () => {
|
||||
markSettingsDirty(true);
|
||||
scheduleSettingsAutoSave();
|
||||
});
|
||||
input?.addEventListener('blur', () => {
|
||||
saveSettings({ silent: true }).catch(() => { });
|
||||
});
|
||||
});
|
||||
|
||||
selectMailProvider.addEventListener('change', async () => {
|
||||
const previousProvider = latestState?.mailProvider || '';
|
||||
const previousMail2925Mode = latestState?.mail2925Mode;
|
||||
@@ -6519,6 +6570,7 @@ chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
|
||||
applyAutoRunStatus(currentAutoRun);
|
||||
updateProgressCounter();
|
||||
updateButtonStates();
|
||||
renderPayPalAccounts();
|
||||
renderHotmailAccounts();
|
||||
renderMail2925Accounts();
|
||||
if (isLuckmailProvider()) {
|
||||
@@ -6721,6 +6773,9 @@ chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
|
||||
inputEmail.value = getCurrentHotmailEmail();
|
||||
}
|
||||
}
|
||||
if (message.payload.currentPayPalAccountId !== undefined || message.payload.paypalAccounts !== undefined) {
|
||||
renderPayPalAccounts();
|
||||
}
|
||||
if (message.payload.currentMail2925AccountId !== undefined || message.payload.mail2925Accounts !== undefined) {
|
||||
renderMail2925Accounts();
|
||||
if (selectMailProvider.value === '2925') {
|
||||
|
||||
Reference in New Issue
Block a user