()
| 1147 | if (UI.autoImportResultList) setFieldError(UI.autoImportResultList, false); |
| 1148 | } |
| 1149 | async function createDorkList() { |
| 1150 | const listNameInputEl = UI.listNameInput; |
| 1151 | const isResultCheckboxEl = UI.isResultListCheckbox; |
| 1152 | if (!listNameInputEl || !isResultCheckboxEl) { |
| 1153 | console.error("Missing UI elements for list creation."); |
| 1154 | showModal("UI Error: Cannot create list."); |
| 1155 | return; |
| 1156 | } |
| 1157 | const listNameValue = listNameInputEl.value.trim(); |
| 1158 | if (!validateListName(listNameValue)) { |
| 1159 | showModal( |
| 1160 | "Invalid list name (A-Z, a-z, 0-9, -, max 15 chars, avoid reserved prefixes)." |
| 1161 | ); |
| 1162 | return; |
| 1163 | } |
| 1164 | const isResult = isResultCheckboxEl.checked; |
| 1165 | const prefix = isResult |
| 1166 | ? CONSTANTS.LIST_PREFIX_RESULT |
| 1167 | : CONSTANTS.LIST_PREFIX_DORK; |
| 1168 | const categoryType = isResult ? "Result" : "Dork"; |
| 1169 | const listStorageKey = `${prefix}${listNameValue}`; |
| 1170 | try { |
| 1171 | const data = await getStorageData(listStorageKey); |
| 1172 | if (typeof data[listStorageKey] !== "undefined") { |
| 1173 | showModal( |
| 1174 | `Error: List "${listNameValue}" already exists as a ${categoryType} list.` |
| 1175 | ); |
| 1176 | return; |
| 1177 | } |
| 1178 | const updatedAtKey = getListUpdatedAtStorageKey(listStorageKey); |
| 1179 | await setStorageData({ |
| 1180 | [listStorageKey]: [], |
| 1181 | ...(updatedAtKey ? { [updatedAtKey]: new Date().toISOString() } : {}), |
| 1182 | }); |
| 1183 | showSuccessAnimation("List created!"); |
| 1184 | await loadAndPopulateLists(); |
| 1185 | listNameInputEl.value = ""; |
| 1186 | isResultCheckboxEl.checked = false; |
| 1187 | selectOptionByValue(UI.listTab2, listStorageKey); |
| 1188 | selectOptionByValue(UI.listDelDropdown, listStorageKey); |
| 1189 | if (!isResult && UI.listTab1) { |
| 1190 | selectOptionByValue(UI.listTab1, listStorageKey); |
| 1191 | UI.listTab1.dispatchEvent(new Event("change")); |
| 1192 | } |
| 1193 | if (UI.listTab2.value === listStorageKey) { |
| 1194 | UI.listTab2.dispatchEvent(new Event("change")); |
| 1195 | } |
| 1196 | } catch (error) { |
| 1197 | console.error("Error creating dork list:", error); |
| 1198 | showModal(`Error saving list: ${error.message}`); |
| 1199 | } |
| 1200 | } |
| 1201 | function validateListName(name) { |
| 1202 | const listName = name?.trim(); |
| 1203 | if (!listName || !/^[a-zA-Z0-9-]{1,15}$/.test(listName)) return false; |
nothing calls this directly
no test coverage detected