feat(ip-proxy): 添加 IP 代理面板的展开/收起功能及持久化状态支持
This commit is contained in:
+69
-19
@@ -14,6 +14,47 @@ const ipProxyActionState = {
|
||||
busy: false,
|
||||
action: '',
|
||||
};
|
||||
const IP_PROXY_SECTION_EXPANDED_STORAGE_KEY = 'multipage-ip-proxy-section-expanded';
|
||||
let ipProxySectionExpanded = false;
|
||||
|
||||
function readIpProxySectionExpanded() {
|
||||
try {
|
||||
return globalThis.localStorage?.getItem(IP_PROXY_SECTION_EXPANDED_STORAGE_KEY) === '1';
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function persistIpProxySectionExpanded(expanded) {
|
||||
try {
|
||||
if (expanded) {
|
||||
globalThis.localStorage?.setItem(IP_PROXY_SECTION_EXPANDED_STORAGE_KEY, '1');
|
||||
} else {
|
||||
globalThis.localStorage?.removeItem(IP_PROXY_SECTION_EXPANDED_STORAGE_KEY);
|
||||
}
|
||||
} catch (err) {
|
||||
// Ignore storage errors; the in-memory collapsed state is still enough for this session.
|
||||
}
|
||||
}
|
||||
|
||||
function setIpProxySectionExpanded(expanded) {
|
||||
ipProxySectionExpanded = Boolean(expanded);
|
||||
persistIpProxySectionExpanded(ipProxySectionExpanded);
|
||||
if (typeof updateIpProxyUI === 'function') {
|
||||
updateIpProxyUI(latestState);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleIpProxySectionExpanded() {
|
||||
setIpProxySectionExpanded(!ipProxySectionExpanded);
|
||||
}
|
||||
|
||||
function initIpProxySectionExpandedState() {
|
||||
ipProxySectionExpanded = readIpProxySectionExpanded();
|
||||
if (typeof updateIpProxyUI === 'function') {
|
||||
updateIpProxyUI(latestState);
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeIpProxyActionType(value = '') {
|
||||
const normalized = String(value || '').trim().toLowerCase();
|
||||
@@ -1158,6 +1199,7 @@ function setIpProxyEnabledInlineStatus(state = {}, enabled = getSelectedIpProxyE
|
||||
|
||||
function updateIpProxyUI(state = latestState) {
|
||||
const enabled = getSelectedIpProxyEnabled();
|
||||
const showSettings = enabled && ipProxySectionExpanded;
|
||||
const mode = getSelectedIpProxyMode();
|
||||
const service = normalizeIpProxyService(selectIpProxyService?.value || state?.ipProxyService || DEFAULT_IP_PROXY_SERVICE);
|
||||
const apiModeAvailable = isIpProxyApiModeAvailable();
|
||||
@@ -1175,59 +1217,67 @@ function updateIpProxyUI(state = latestState) {
|
||||
if (rowIpProxyEnabled) {
|
||||
rowIpProxyEnabled.style.display = '';
|
||||
}
|
||||
if (btnToggleIpProxySection) {
|
||||
btnToggleIpProxySection.disabled = !enabled;
|
||||
btnToggleIpProxySection.textContent = showSettings ? '收起设置' : '展开设置';
|
||||
btnToggleIpProxySection.title = enabled
|
||||
? (showSettings ? '收起 IP 代理设置' : '展开 IP 代理设置')
|
||||
: '开启 IP 代理后可展开设置';
|
||||
btnToggleIpProxySection.setAttribute('aria-expanded', String(showSettings));
|
||||
}
|
||||
if (rowIpProxyFold) {
|
||||
rowIpProxyFold.style.display = enabled ? '' : 'none';
|
||||
rowIpProxyFold.style.display = showSettings ? '' : 'none';
|
||||
}
|
||||
if (rowIpProxyService) {
|
||||
rowIpProxyService.style.display = enabled ? '' : 'none';
|
||||
rowIpProxyService.style.display = showSettings ? '' : 'none';
|
||||
}
|
||||
if (rowIpProxyMode) {
|
||||
rowIpProxyMode.style.display = enabled ? '' : 'none';
|
||||
rowIpProxyMode.style.display = showSettings ? '' : 'none';
|
||||
}
|
||||
if (rowIpProxyLayout) {
|
||||
rowIpProxyLayout.style.display = enabled ? '' : 'none';
|
||||
rowIpProxyLayout.style.display = showSettings ? '' : 'none';
|
||||
}
|
||||
if (rowIpProxyApiUrl) {
|
||||
rowIpProxyApiUrl.style.display = enabled && apiModeAvailable && isApiMode ? '' : 'none';
|
||||
rowIpProxyApiUrl.style.display = showSettings && apiModeAvailable && isApiMode ? '' : 'none';
|
||||
}
|
||||
if (rowIpProxyAccountList) {
|
||||
rowIpProxyAccountList.style.display = enabled && isAccountMode && accountListAvailable ? '' : 'none';
|
||||
rowIpProxyAccountList.style.display = showSettings && isAccountMode && accountListAvailable ? '' : 'none';
|
||||
}
|
||||
if (rowIpProxyAccountSessionPrefix) {
|
||||
rowIpProxyAccountSessionPrefix.style.display = enabled && showSessionOptions ? '' : 'none';
|
||||
rowIpProxyAccountSessionPrefix.style.display = showSettings && showSessionOptions ? '' : 'none';
|
||||
}
|
||||
if (rowIpProxyAccountLifeMinutes) {
|
||||
rowIpProxyAccountLifeMinutes.style.display = enabled && showSessionOptions ? '' : 'none';
|
||||
rowIpProxyAccountLifeMinutes.style.display = showSettings && showSessionOptions ? '' : 'none';
|
||||
}
|
||||
if (rowIpProxyPoolTargetCount) {
|
||||
rowIpProxyPoolTargetCount.style.display = enabled ? '' : 'none';
|
||||
rowIpProxyPoolTargetCount.style.display = showSettings ? '' : 'none';
|
||||
}
|
||||
if (rowIpProxyHost) {
|
||||
rowIpProxyHost.style.display = enabled && isAccountMode ? '' : 'none';
|
||||
rowIpProxyHost.style.display = showSettings && isAccountMode ? '' : 'none';
|
||||
}
|
||||
if (rowIpProxyPort) {
|
||||
rowIpProxyPort.style.display = enabled && isAccountMode ? '' : 'none';
|
||||
rowIpProxyPort.style.display = showSettings && isAccountMode ? '' : 'none';
|
||||
}
|
||||
if (rowIpProxyProtocol) {
|
||||
rowIpProxyProtocol.style.display = enabled ? '' : 'none';
|
||||
rowIpProxyProtocol.style.display = showSettings ? '' : 'none';
|
||||
}
|
||||
if (rowIpProxyUsername) {
|
||||
rowIpProxyUsername.style.display = enabled && isAccountMode ? '' : 'none';
|
||||
rowIpProxyUsername.style.display = showSettings && isAccountMode ? '' : 'none';
|
||||
}
|
||||
if (rowIpProxyPassword) {
|
||||
rowIpProxyPassword.style.display = enabled && isAccountMode ? '' : 'none';
|
||||
rowIpProxyPassword.style.display = showSettings && isAccountMode ? '' : 'none';
|
||||
}
|
||||
if (rowIpProxyRegion) {
|
||||
rowIpProxyRegion.style.display = enabled && isAccountMode ? '' : 'none';
|
||||
rowIpProxyRegion.style.display = showSettings && isAccountMode ? '' : 'none';
|
||||
}
|
||||
if (rowIpProxyActions) {
|
||||
rowIpProxyActions.style.display = enabled ? '' : 'none';
|
||||
rowIpProxyActions.style.display = showSettings ? '' : 'none';
|
||||
}
|
||||
if (ipProxyActionButtons) {
|
||||
ipProxyActionButtons.style.display = enabled ? '' : 'none';
|
||||
ipProxyActionButtons.style.display = showSettings ? '' : 'none';
|
||||
}
|
||||
if (rowIpProxyRuntimeStatus) {
|
||||
rowIpProxyRuntimeStatus.style.display = enabled ? '' : 'none';
|
||||
rowIpProxyRuntimeStatus.style.display = showSettings ? '' : 'none';
|
||||
}
|
||||
if (ipProxyLayout) {
|
||||
ipProxyLayout.classList.toggle('is-account-only', !apiModeAvailable);
|
||||
@@ -1254,7 +1304,7 @@ function updateIpProxyUI(state = latestState) {
|
||||
ipProxyApiPanel.classList.toggle('is-disabled', !apiModeAvailable);
|
||||
ipProxyApiPanel.setAttribute('aria-disabled', String(!apiModeAvailable));
|
||||
ipProxyApiPanel.hidden = !apiModeAvailable;
|
||||
ipProxyApiPanel.style.display = enabled && apiModeAvailable ? '' : 'none';
|
||||
ipProxyApiPanel.style.display = showSettings && apiModeAvailable ? '' : 'none';
|
||||
}
|
||||
if (inputIpProxyApiUrl) {
|
||||
inputIpProxyApiUrl.disabled = !enabled || !apiModeAvailable;
|
||||
|
||||
Reference in New Issue
Block a user