()
| 635 | } |
| 636 | } |
| 637 | async function initializeApp() { |
| 638 | try { |
| 639 | await dbStorage.init().catch((error) => {}); |
| 640 | mapping = await loadMapping(); |
| 641 | initializeScrollListener(); |
| 642 | |
| 643 | for (let i = 0; i <= CONFIG.indexPreloadCount; i++) { |
| 644 | indexCache.preload(i, CONFIG.imageBaseUrl).catch((error) => {}); |
| 645 | } |
| 646 | |
| 647 | if ( |
| 648 | window.subtitleDB && |
| 649 | !window.subtitleDB.isLoaded && |
| 650 | !window.subtitleDB.isLoading |
| 651 | ) { |
| 652 | window.subtitleDB |
| 653 | .load() |
| 654 | .then(() => { |
| 655 | AppState.dbLoaded = true; |
| 656 | }) |
| 657 | .catch((error) => { |
| 658 | setTimeout(() => { |
| 659 | window.subtitleDB.load().catch((err) => {}); |
| 660 | }, 3000); |
| 661 | }); |
| 662 | } |
| 663 | |
| 664 | document |
| 665 | .getElementById("searchForm") |
| 666 | .addEventListener("submit", async (e) => { |
| 667 | e.preventDefault(); |
| 668 | if (AppState.isSearching) return; |
| 669 | AppState.isSearching = true; |
| 670 | try { |
| 671 | await handleSearch(e); |
| 672 | } finally { |
| 673 | AppState.isSearching = false; |
| 674 | } |
| 675 | }); |
| 676 | |
| 677 | document.getElementById("query").addEventListener("keydown", (e) => { |
| 678 | if (e.key === "Enter") { |
| 679 | e.preventDefault(); |
| 680 | if (AppState.isSearching) return; |
| 681 | document |
| 682 | .getElementById("searchForm") |
| 683 | .dispatchEvent(new Event("submit")); |
| 684 | } |
| 685 | }); |
| 686 | |
| 687 | document |
| 688 | .getElementById("refreshDiv") |
| 689 | .addEventListener("click", function () { |
| 690 | location.reload(); |
| 691 | }); |
| 692 | |
| 693 | document |
| 694 | .getElementById("semanticToggle") |
no test coverage detected