feat(sidepanel): 添加密码可见性切换功能及相关测试
This commit is contained in:
@@ -4524,6 +4524,54 @@ function syncToggleButtonLabel(button, input, labels) {
|
||||
button.title = isHidden ? labels.show : labels.hide;
|
||||
}
|
||||
|
||||
function getPasswordToggleLabels(button) {
|
||||
if (!button) {
|
||||
return {
|
||||
show: '\u663e\u793a\u5185\u5bb9',
|
||||
hide: '\u9690\u85cf\u5185\u5bb9',
|
||||
};
|
||||
}
|
||||
const show = button.dataset?.showLabel
|
||||
|| button.getAttribute('aria-label')
|
||||
|| button.title
|
||||
|| '\u663e\u793a\u5185\u5bb9';
|
||||
const hide = button.dataset?.hideLabel
|
||||
|| String(show).replace(/^\u663e\u793a/, '\u9690\u85cf')
|
||||
|| '\u9690\u85cf\u5185\u5bb9';
|
||||
return { show, hide };
|
||||
}
|
||||
|
||||
function syncPasswordVisibilityToggle(button) {
|
||||
const targetId = String(button?.dataset?.passwordToggle || '').trim();
|
||||
const input = targetId ? document.getElementById(targetId) : null;
|
||||
if (!button || !input) return;
|
||||
syncToggleButtonLabel(button, input, getPasswordToggleLabels(button));
|
||||
}
|
||||
|
||||
function syncPasswordVisibilityToggles(root = document) {
|
||||
root.querySelectorAll?.('[data-password-toggle]').forEach(syncPasswordVisibilityToggle);
|
||||
}
|
||||
|
||||
function bindPasswordVisibilityToggles(root = document) {
|
||||
root.querySelectorAll?.('[data-password-toggle]').forEach((button) => {
|
||||
if (button.dataset?.passwordToggleBound === 'true') {
|
||||
syncPasswordVisibilityToggle(button);
|
||||
return;
|
||||
}
|
||||
if (button.dataset) {
|
||||
button.dataset.passwordToggleBound = 'true';
|
||||
}
|
||||
syncPasswordVisibilityToggle(button);
|
||||
button.addEventListener('click', () => {
|
||||
const targetId = String(button.dataset?.passwordToggle || '').trim();
|
||||
const input = targetId ? document.getElementById(targetId) : null;
|
||||
if (!input) return;
|
||||
input.type = input.type === 'password' ? 'text' : 'password';
|
||||
syncPasswordVisibilityToggle(button);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function copyTextToClipboard(text) {
|
||||
const value = String(text || '').trim();
|
||||
if (!value) {
|
||||
@@ -6981,6 +7029,7 @@ document.addEventListener('scroll', () => {
|
||||
// ============================================================
|
||||
|
||||
initializeManualStepActions();
|
||||
bindPasswordVisibilityToggles();
|
||||
initTheme();
|
||||
initHotmailListExpandedState();
|
||||
initMail2925ListExpandedState();
|
||||
@@ -7001,6 +7050,7 @@ loadHeroSmsCountries().catch((err) => {
|
||||
syncIpProxyApiUrlToggleLabel();
|
||||
syncIpProxyUsernameToggleLabel();
|
||||
syncIpProxyPasswordToggleLabel();
|
||||
syncPasswordVisibilityToggles();
|
||||
updatePanelModeUI();
|
||||
updateButtonStates();
|
||||
updateStatusDisplay(latestState);
|
||||
|
||||
Reference in New Issue
Block a user