const fixAutofillAttributes = () => {
// 이메일 필드 타겟팅
const emailInputs = document.querySelectorAll('input[type="email"], input[name*="email"]');
emailInputs.forEach(input => {
if (!input.hasAttribute('autocomplete')) {
input.setAttribute('autocomplete', 'email');
}
});
// 비밀번호 필드 타겟팅
const passwordInputs = document.querySelectorAll('input[type="password"]');
passwordInputs.forEach(input => {
if (!input.hasAttribute('autocomplete')) {
// 로그인 폼인 경우 current-password, 가입 폼인 경우 new-password가 적절하나
// 범용적으로 current-password를 우선 적용하거나 폼 ID를 체크합니다.
input.setAttribute('autocomplete', 'current-password');
}
});
// 이름 필드 타겟팅
const nameInputs = document.querySelectorAll('input[name*="first_name"], input[name*="last_name"], input[name*="name"]:not([type="email"])');
nameInputs.forEach(input => {
if (!input.hasAttribute('autocomplete')) {
input.setAttribute('autocomplete', 'name');
}
});
};
// 실행
fixAutofillAttributes();
// 동적 폼 로드 대비 지연 실행
setTimeout(fixAutofillAttributes, 2000);
const cleanupAria = () => {
// 불필요하거나 비어있는 ARIA 속성 제거
document.querySelectorAll('[aria-haspopup=""], [aria-controls=""]').forEach(el => {
if (!el.getAttribute('aria-controls')) el.removeAttribute('aria-controls');
if (!el.getAttribute('aria-haspopup')) el.removeAttribute('aria-haspopup');
});
// 제품 카드 등에 논리적 그룹 역할 부여
document.querySelectorAll('.product-card, .grid__item, .card').forEach(card => {
if (!card.hasAttribute('role')) card.setAttribute('role', 'group');
if (!card.hasAttribute('aria-label')) card.setAttribute('aria-label', 'Product item');
});
};
// 패치 실행 순서
fixFakeButtons(); fixCarousels(); cleanupAria();
})();