// चूँकि यह बाहरी स्क्रिप्ट है, इसे यहाँ JS में लोड नहीं कर सकते, आपको इसे HTML में डालना होगा।
// फिलहाल, हम पिछली रेगेक्स आधारित विधि का उपयोग करेंगे।
function clearSearchHighlights() { /* पहले जैसा */
contentToSearch.forEach(paragraph => {
const marks = paragraph.querySelectorAll('mark');
marks.forEach(mark => {
const parent = mark.parentNode;
parent.replaceChild(document.createTextNode(mark.textContent), mark);
});
paragraph.normalize();
});
}
function performSearch() { /* पहले जैसा */
clearSearchHighlights();
const searchTerm = searchInput.value.trim();
if (searchTerm === "") { return; }
const regex = new RegExp(searchTerm.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'gi');
let found = false;
let firstMatchElement = null;
contentToSearch.forEach(paragraph => {
const walker = document.createTreeWalker(paragraph, NodeFilter.SHOW_TEXT, null, false);
let node; let nodesToReplace = [];
while (node = walker.nextNode()) {
const text = node.nodeValue; let lastIndex = 0; let match;
const newNodeContainer = document.createDocumentFragment();
while ((match = regex.exec(text)) !== null) {
found = true;
newNodeContainer.appendChild(document.createTextNode(text.substring(lastIndex, match.index)));
const mark = document.createElement('mark');
mark.textContent = match[0];
newNodeContainer.appendChild(mark);
if (!firstMatchElement) { firstMatchElement = mark; }
lastIndex = regex.lastIndex;
}
newNodeContainer.appendChild(document.createTextNode(text.substring(lastIndex)));
if (newNodeContainer.childNodes.length > 1 || (newNodeContainer.firstChild && newNodeContainer.firstChild.nodeType !== Node.TEXT_NODE)) {
nodesToReplace.push({ original: node, replacement: newNodeContainer });
}
}
nodesToReplace.forEach(item => { item.original.parentNode.replaceChild(item.replacement, item.original); });
});
if (!found) { alert(`"${searchTerm}" नहीं मिला।`); }
else if (firstMatchElement) {
const offsetTop = firstMatchElement.getBoundingClientRect().top + window.pageYOffset; // सही ऑफसेट
window.scrollTo({ top: offsetTop - navHeight - 80, behavior: 'smooth' });
// firstMatchElement.focus(); // फोकस अक्सर काम नहीं करता
}
}
searchButton.addEventListener('click', performSearch);
searchInput.addEventListener('keyup', function(event) {
if (event.key === 'Enter') { performSearch(); }
else if (searchInput.value.trim() === "") { clearSearchHighlights(); }
});
// --- सर्च कार्यक्षमता समाप्त ---
// --- स्वचालित पेजिनेशन ---
function setupPagination() {
const paginationContainer = document.querySelector('.pagination-section');
if (!paginationContainer) { console.warn("Pagination container not found."); return; }
const totalPages = 6;
const baseFilename = 'aranyani-kaushik-part'; // ** यह नाम बदलें **
const fileExtension = '.html';
let currentPageNumber = 1;
try {
const pathParts = window.location.pathname.split('/'); const filename = pathParts.pop() || pathParts.pop();
const match = filename.match(/part(\d+)/i);
if (match && match[1]) {
const num = parseInt(match[1], 10);
if (!isNaN(num) && num >= 1 && num <= totalPages) { currentPageNumber = num; }
else { console.warn(`Pagination: Page number ${num} invalid.`); currentPageNumber = 1; }
} else { console.warn("Pagination: No page number in URL."); currentPageNumber = 1; }
} catch (e) { console.error("Pagination Error:", e); currentPageNumber = 1; }
paginationContainer.innerHTML = '';
const prevLink = document.createElement('a'); prevLink.textContent = '‹ पिछला'; prevLink.classList.add('pagination-link');
if (currentPageNumber > 1) { prevLink.href = `${baseFilename}${currentPageNumber - 1}${fileExtension}`; }
else { prevLink.classList.add('disabled'); prevLink.href = "#"; }
paginationContainer.appendChild(prevLink);
const startPage = Math.max(1, currentPageNumber - 4); const endPage = Math.min(totalPages, currentPageNumber + 1);
if (startPage > 1) { // यदि पहले पेज से गैप है
const firstLink = document.createElement('a'); firstLink.href = `${baseFilename}1${fileExtension}`; firstLink.textContent = 1; firstLink.classList.add('pagination-link'); paginationContainer.appendChild(firstLink);
if (startPage > 2) { const ellipsis = document.createElement('span'); ellipsis.textContent = '...'; ellipsis.classList.add('pagination-label'); paginationContainer.appendChild(ellipsis); }
}
for (let i = startPage; i <= endPage; i++) {
if (i === currentPageNumber) { const currentSpan = document.createElement('span'); currentSpan.textContent = i; currentSpan.classList.add('pagination-link', 'current'); paginationContainer.appendChild(currentSpan); }
else { const link = document.createElement('a'); link.href = `${baseFilename}${i}${fileExtension}`; link.textContent = i; link.classList.add('pagination-link'); paginationContainer.appendChild(link); }
}
if (endPage < totalPages) { // यदि अंतिम पेज से गैप है
if (endPage < totalPages - 1) { const ellipsis = document.createElement('span'); ellipsis.textContent = '...'; ellipsis.classList.add('pagination-label'); paginationContainer.appendChild(ellipsis); }
const lastLink = document.createElement('a'); lastLink.href = `${baseFilename}${totalPages}${fileExtension}`; lastLink.textContent = totalPages; lastLink.classList.add('pagination-link'); paginationContainer.appendChild(lastLink);
}
const nextLink = document.createElement('a'); nextLink.textContent = 'अगला ›'; nextLink.classList.add('pagination-link');
if (currentPageNumber < totalPages) { nextLink.href = `${baseFilename}${currentPageNumber + 1}${fileExtension}`; }
else { nextLink.classList.add('disabled'); nextLink.href = "#"; }
paginationContainer.appendChild(nextLink);
}
setupPagination();
// --- स्वचालित पेजिनेशन समाप्त ---
// --- TTS कार्यक्षमता ---
function speakText(text, lang = "hi-IN") { if ('speechSynthesis' in window) { window.speechSynthesis.cancel(); const speech = new SpeechSynthesisUtterance(text); speech.lang = lang; speech.volume = 1; speech.rate = 0.9; speech.pitch = 1; window.speechSynthesis.speak(speech); } else { console.warn("Speech synthesis not supported."); } }
const specialTermElements = document.querySelectorAll(".special-term-1, .special-term-2, .special-term-3");
specialTermElements.forEach(term => { term.addEventListener("click", (event) => { event.stopPropagation(); const textToSpeak = term.textContent; speakText(textToSpeak, "hi-IN"); }); term.title = "सुनने के लिए क्लिक करें"; });
const paragraphElements = document.querySelectorAll(".custom-p");
paragraphElements.forEach(paragraph => { if (!paragraph.closest('.story-description')) { paragraph.addEventListener("click", () => { const textToSpeak = paragraph.textContent; speakText(textToSpeak, "hi-IN"); }); paragraph.title = "पूरा पैराग्राफ सुनने के लिए क्लिक करें"; paragraph.addEventListener("mouseenter", () => { paragraph.style.color = "#C71585"; paragraph.style.textShadow = "1px 1px 3px rgba(0, 0, 0, 0.2)"; }); paragraph.addEventListener("mouseout", () => { paragraph.style.color = ""; paragraph.style.textShadow = ""; }); } else { paragraph.style.cursor = "default"; } });
}); // DOMContentLoaded समाप्त
Post a Comment
0
Comments
Popular Post
Social Plugin
वीडियो खोजे जा रहे हैं...त्रुटि: API कुंजी कॉन्फ़िगर नहीं है या अमान्य है।त्रुटि: YouTube API कोटा समाप्त हो गया है।त्रुटि: API कुंजी अमान्य है।इस खोज के लिए कोई वीडियो नहीं मिला।चयनित वीडियो लोड करने में विफल।API त्रुटिवीडियो लोड करने में त्रुटिएक आंतरिक त्रुटि हुई।कृपया कम से कम दो विकल्प चुनें या टेक्स्ट बॉक्स में टाइप करें।
AIzaSyBYVKCeEIlBjCoS6Xy_mWatJywG3hUPv3Q
अरे रुको! मज़ा नहीं आ रहा? 🤔 खोजो अपनी पसंद का कंटेंट - पढ़ाई, मनोरंजन, एग्जाम टिप्स और लाइव न्यूज़! 📰📚🎉
ऊब गए हो? 🤔 हम आपकी पढ़ाई, मनोरंजन, और परीक्षा की तैयारी को आसान बनाते हैं!🚀 साथ ही, पाएं ताज़ा ख़बरें! 📰 अभी एक्सप्लोर करें! 🔍
नीचे दिए बटनों से चुनें अपनी पसंद की दुनिया - पढ़ाई, मज़ा, तैयारी, या ताज़ा खबरें!
0 Comments