워치 컨트롤 f 리셋 버튼 왼쪽 위치이동 최종 끝?
<!-- 워치 컨트롤 f 위치 표시 -->
<div id="fixed-search-bar" style="position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); width: calc(100% - 30px); max-width: 500px; background: rgba(30, 30, 30, 0.85); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); color: white; padding: 10px 14px; box-sizing: border-box; display: flex; align-items: center; gap: 8px; z-index: 99999; border-radius: 16px; box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3); border: 1px solid rgba(255, 255, 255, 0.15);">
<button class="reset-btn" onclick="resetSearch()" style="padding: 12px 14px; font-size: 13px; font-weight: 600; background-color: #4b5563; color: white; border: none; border-radius: 10px; cursor: pointer; white-space: nowrap; transition: background 0.2s;">리셋</button>
<input type="text" id="searchInput" placeholder="검색어 입력..." style="padding: 10px 12px; font-size: 14px; border: none; border-radius: 10px; outline: none; color: #111; background-color: #f0f0f2; width: 100px; min-width: 80px; transition: background 0.2s;">
<span id="resultCount" style="font-size: 13px; color: #fbbf24; font-weight: 600; white-space: nowrap; min-width: 35px; text-align: center;">0 / 0</span>
<button onclick="movePrev()" style="padding: 12px 16px; font-size: 16px; font-weight: 600; background-color: #3b82f6; color: white; border: none; border-radius: 10px; cursor: pointer; white-space: nowrap; transition: background 0.2s;">▲</button>
<button onclick="moveNext()" style="padding: 12px 16px; font-size: 16px; font-weight: 600; background-color: #3b82f6; color: white; border: none; border-radius: 10px; cursor: pointer; white-space: nowrap; transition: background 0.2s;">▼</button>
</div>
<style>
/* 본문 하단이 검색바에 가리지 않도록 여백 추가 */
body {
padding-bottom: 100px !important;
}
/* 형광펜 스타일 (부드러운 노란색 계열) */
.search-highlight {
background-color: #fef08a !important;
color: #111 !important;
border-radius: 3px;
padding: 0 2px;
}
/* 현재 선택된 단어 (모던한 주황색 포인트) */
.search-highlight.active {
background-color: #f97316 !important;
color: white !important;
font-weight: bold;
box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.4);
}
</style>
<script>
let matches = [];
let currentIndex = -1;
// 입력 시 실시간 검색 실행
document.getElementById('searchInput').addEventListener('input', function() {
const keyword = this.value.trim();
clearHighlights();
if (!keyword) return;
highlightTextNodes(document.body, keyword);
matches = document.querySelectorAll('.search-highlight');
const countElem = document.getElementById('resultCount');
if (matches.length > 0) {
currentIndex = 0;
updateActiveMatch();
} else {
currentIndex = -1;
countElem.textContent = `0 / 0`;
}
});
function highlightTextNodes(element, keyword) {
if (!element) return;
for (let node of Array.from(element.childNodes)) {
if (node.nodeType === 3) {
const text = node.nodeValue;
const escapedKeyword = escapeRegExp(keyword);
const regex = new RegExp(`(${escapedKeyword})`, 'gi');
if (regex.test(text)) {
const wrapper = document.createElement('span');
wrapper.innerHTML = text.replace(regex, '<span class="search-highlight">$1</span>');
node.parentNode.replaceChild(wrapper, node);
}
} else if (node.nodeType === 1) {
if (node.nodeName === 'SCRIPT' || node.nodeName === 'STYLE' || node.id === 'fixed-search-bar') {
continue;
}
highlightTextNodes(node, keyword);
}
}
}
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
function clearHighlights() {
const highlights = document.querySelectorAll('.search-highlight');
highlights.forEach(el => {
const parent = el.parentNode;
if (parent) {
parent.replaceChild(document.createTextNode(el.textContent), el);
parent.normalize();
}
});
matches = [];
currentIndex = -1;
const countElem = document.getElementById('resultCount');
if (countElem) countElem.textContent = '0 / 0';
}
function moveNext() {
if (matches.length === 0) return;
currentIndex = (currentIndex + 1) % matches.length;
updateActiveMatch();
}
function movePrev() {
if (matches.length === 0) return;
currentIndex = (currentIndex - 1 + matches.length) % matches.length;
updateActiveMatch();
}
function updateActiveMatch() {
matches.forEach((el, idx) => {
if (idx === currentIndex) {
el.classList.add('active');
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
} else {
el.classList.remove('active');
}
});
const countElem = document.getElementById('resultCount');
if (countElem) {
countElem.textContent = `${currentIndex + 1} / ${matches.length}`;
}
}
function resetSearch() {
document.getElementById('searchInput').value = '';
clearHighlights();
}
</script>
<!-- 워치 컨트롤 f 위치 표시 -->