135 Countries Are Listening | New Bible Reader | Read the Bible in 36 Languages
Prayer Requests
(function () { const API = "https://inthefield-bible-reader.inthefieldaudiobible2021.workers.dev"; const languageSelect = document.getElementById("ifa-language"); const versionSelect = document.getElementById("ifa-audio-version"); const bookSelect = document.getElementById("ifa-audio-book"); const chapterSelect = document.getElementById("ifa-audio-chapter"); const status = document.getElementById("ifa-audio-status"); const player = document.getElementById("ifa-audio-player"); if (!languageSelect || !versionSelect || !bookSelect || !chapterSelect || !status || !player) return; let audioBibles = []; function setStatus(message) { status.textContent = message; } function resetSelect(select, message) { select.innerHTML = ""; const option = document.createElement("option"); option.value = ""; option.textContent = message; select.appendChild(option); select.disabled = true; } function addOptions(select, items, getValue, getLabel, placeholder) { resetSelect(select, placeholder); items.forEach(function (item) { const option = document.createElement("option"); option.value = getValue(item); option.textContent = getLabel(item); select.appendChild(option); }); select.disabled = items.length === 0; } async function getData(path) { const response = await fetch(API + path); if (!response.ok) { throw new Error("The server returned an error: " + response.status); } const result = await response.json(); return result.data; } function languageName(bible) { const language = bible.language || {}; return language.nameLocal || language.name || "Other languages"; } async function loadAudioBibles() { try { setStatus("Loading available audio Bibles..."); audioBibles = await getData("/api/audio-bibles"); if (!Array.isArray(audioBibles) || audioBibles.length === 0) { throw new Error("No audio Bibles were returned."); } const languages = [...new Set(audioBibles.map(languageName))] .sort(function (a, b) { return a.localeCompare(b); }); addOptions( languageSelect, languages, function (language) { return language; }, function (language) { return language; }, "Choose a language" ); setStatus("Choose a language to begin listening."); } catch (error) { setStatus("Sorry, we couldn't load the audio Bibles. Please refresh the page and try again."); console.error("Audio Bible error:", error); } } languageSelect.addEventListener("change", function () { const selectedLanguage = languageSelect.value; resetSelect(versionSelect, "Choose an audio Bible"); resetSelect(bookSelect, "Choose a book"); resetSelect(chapterSelect, "Choose a chapter"); player.pause(); player.removeAttribute("src"); player.style.display = "none"; if (!selectedLanguage) return; const matchingBibles = audioBibles .filter(function (bible) { return languageName(bible) === selectedLanguage; }) .sort(function (a, b) { return (a.name || "").localeCompare(b.name || ""); }); addOptions( versionSelect, matchingBibles, function (bible) { return bible.id; }, function (bible) { return bible.nameLocal || bible.name || bible.id; }, "Choose an audio Bible" ); setStatus("Now choose an audio Bible."); }); versionSelect.addEventListener("change", async function () { const bibleId = versionSelect.value; resetSelect(bookSelect, "Loading books..."); resetSelect(chapterSelect, "Choose a chapter"); player.pause(); player.removeAttribute("src"); player.style.display = "none"; if (!bibleId) { resetSelect(bookSelect, "Choose a book"); return; } try { setStatus("Loading books..."); const books = await getData( "/api/audio-bibles/" + encodeURIComponent(bibleId) + "/books" ); addOptions( bookSelect, books, function (book) { return book.id; }, function (book) { return book.nameLocal || book.name || book.id; }, "Choose a book" ); setStatus("Choose a book."); } catch (error) { resetSelect(bookSelect, "Unable to load books"); setStatus("Sorry, we couldn't load the books. Please try again."); console.error(error); } }); bookSelect.addEventListener("change", async function () { const bibleId = versionSelect.value; const bookId = bookSelect.value; resetSelect(chapterSelect, "Loading chapters..."); player.pause(); player.removeAttribute("src"); player.style.display = "none"; if (!bibleId || !bookId) { resetSelect(chapterSelect, "Choose a chapter"); return; } try { setStatus("Loading chapters..."); const chapters = await getData( "/api/audio-bibles/" + encodeURIComponent(bibleId) + "/books/" + encodeURIComponent(bookId) + "/chapters" ); addOptions( chapterSelect, chapters, function (chapter) { return chapter.id; }, function (chapter) { return chapter.number || chapter.id.split(".").pop(); }, "Choose a chapter" ); setStatus("Choose a chapter to listen."); } catch (error) { resetSelect(chapterSelect, "Unable to load chapters"); setStatus("Sorry, we couldn't load the chapters. Please try again."); console.error(error); } }); chapterSelect.addEventListener("change", async function () { const bibleId = versionSelect.value; const chapterId = chapterSelect.value; player.pause(); player.removeAttribute("src"); player.style.display = "none"; if (!bibleId || !chapterId) return; try { setStatus("Preparing your audio chapter..."); const chapter = await getData( "/api/audio-bibles/" + encodeURIComponent(bibleId) + "/chapters/" + encodeURIComponent(chapterId) ); if (!chapter || !chapter.resourceUrl) { throw new Error("No audio recording was found."); } player.src = chapter.resourceUrl; player.style.display = "block"; player.load(); setStatus("Your chapter is ready. Press Play to listen."); } catch (error) { setStatus("Sorry, we couldn't load that recording. Please try another chapter."); console.error(error); } }); loadAudioBibles(); })(); (function () { function removePrintButton() { document.querySelectorAll(".print-pdf-button").forEach(function (button) { button.remove(); }); } removePrintButton(); const observer = new MutationObserver(removePrintButton); observer.observe(document.body, { childList: true, subtree: true }); })();