참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다.
- 파이어폭스 / 사파리: Shift 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5 또는 Ctrl-R을 입력 (Mac에서는 ⌘-R)
- 구글 크롬: Ctrl-Shift-R키를 입력 (Mac에서는 ⌘-Shift-R)
- 인터넷 익스플로러 / 엣지: Ctrl 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5를 입력.
- 오페라: Ctrl-F5를 입력.
/* 이 자바스크립트 설정은 모든 문서, 모든 사용자에게 적용됩니다. */
/**
* Aggressive autofocus for Citizen search
* - Remembers user intent even during page load
* - Focuses input the moment it becomes available & visible
*/
(function () {
const TOGGLE_SELECTOR =
'#citizen-search-details > summary.citizen-dropdown-summary';
const INPUT_SELECTOR = '#searchInput';
let wantFocus = false;
let observer = null;
let retryTimer = null;
function canFocus(input) {
if (!input) return false;
if (input.disabled) return false;
const rect = input.getBoundingClientRect();
return rect.width > 0 && rect.height > 0;
}
function tryFocus() {
if (!wantFocus) return;
const input = document.querySelector(INPUT_SELECTOR);
if (!canFocus(input)) return;
input.focus({ preventScroll: true });
input.click();
if (document.activeElement === input) {
cleanup();
}
}
function cleanup() {
wantFocus = false;
if (observer) observer.disconnect();
observer = null;
if (retryTimer) clearInterval(retryTimer);
retryTimer = null;
}
function startWatching() {
// 1) DOM 변화 감시
if (!observer) {
observer = new MutationObserver(tryFocus);
observer.observe(document.body, {
childList: true,
subtree: true,
attributes: true,
});
}
// 2) 혹시 Mutation이 안 잡히는 케이스 대비 폴링
if (!retryTimer) {
retryTimer = setInterval(tryFocus, 50);
}
}
function onSearchIntent() {
wantFocus = true;
tryFocus(); // 즉시 한 번
startWatching(); // 안 되면 끝까지 쫓아감
}
// 🔑 진짜 중요한 부분: "유저 제스처"에서 intent만 기록
['touchstart', 'touchend', 'mousedown', 'click'].forEach((evt) => {
document.addEventListener(
evt,
function (e) {
if (e.target.closest(TOGGLE_SELECTOR)) {
onSearchIntent();
}
},
true
);
});
})();