()
| 1741 | } |
| 1742 | } |
| 1743 | async function populateSearchEngineDropdown() { |
| 1744 | console.log("[populateSearchEngineDropdown] Populating engines..."); |
| 1745 | if (!UI.searchengineSelect) return; |
| 1746 | console.log( |
| 1747 | `[populateSearchEngineDropdown] BEFORE clear engine select, options: ${UI.searchengineSelect.options.length}` |
| 1748 | ); |
| 1749 | UI.searchengineSelect.replaceChildren(); |
| 1750 | UI.searchengineSelect.appendChild(createDefaultOption("Search Engine")); |
| 1751 | console.log( |
| 1752 | `[populateSearchEngineDropdown] AFTER default engine select, options: ${UI.searchengineSelect.options.length}` |
| 1753 | ); |
| 1754 | UI.searchengineSelect.value = "0"; |
| 1755 | let engineCount = 0; |
| 1756 | try { |
| 1757 | const data = await getStorageData([ |
| 1758 | CONSTANTS.STORAGE_KEYS.USER_SELECTORS, |
| 1759 | CONSTANTS.STORAGE_KEYS.DEFAULT_SELECTORS, |
| 1760 | ]); |
| 1761 | const userConfigs = data[CONSTANTS.STORAGE_KEYS.USER_SELECTORS] || {}; |
| 1762 | const defaultConfigs = |
| 1763 | data[CONSTANTS.STORAGE_KEYS.DEFAULT_SELECTORS] || {}; |
| 1764 | const allConfigs = { ...defaultConfigs, ...userConfigs }; |
| 1765 | const validEngines = []; |
| 1766 | for (const key in allConfigs) { |
| 1767 | if (Object.prototype.hasOwnProperty.call(allConfigs, key)) { |
| 1768 | const config = allConfigs[key]; |
| 1769 | if (config && config.useInEngineSelect === true && config.baseUrl) { |
| 1770 | validEngines.push({ key: key, config: config }); |
| 1771 | } |
| 1772 | } |
| 1773 | } |
| 1774 | validEngines.sort(sortSearchEngines); |
| 1775 | if (validEngines.length === 0) { |
| 1776 | console.warn("No search engines found eligible for dropdown."); |
| 1777 | } else { |
| 1778 | validEngines.forEach((engineData) => { |
| 1779 | let displayName = engineData.key; |
| 1780 | const domainParts = engineData.key.split("."); |
| 1781 | if (domainParts.length >= 2) |
| 1782 | displayName = domainParts[domainParts.length - 2]; |
| 1783 | displayName = |
| 1784 | displayName.charAt(0).toUpperCase() + displayName.slice(1); |
| 1785 | const truncatedDisplayName = truncateText(displayName, 15); |
| 1786 | const option = document.createElement("option"); |
| 1787 | option.value = engineData.key; |
| 1788 | option.textContent = truncatedDisplayName; |
| 1789 | option.title = engineData.key; |
| 1790 | UI.searchengineSelect.appendChild(option); |
| 1791 | engineCount++; |
| 1792 | }); |
| 1793 | } |
| 1794 | UI.searchengineSelect.disabled = engineCount === 0; |
| 1795 | await loadSavedOptions(); |
| 1796 | } catch (error) { |
| 1797 | console.error("Error populating search engine dropdown:", error); |
| 1798 | UI.searchengineSelect.replaceChildren(); |
| 1799 | UI.searchengineSelect.appendChild(createDefaultOption("Error Loading")); |
| 1800 | UI.searchengineSelect.disabled = true; |
no test coverage detected