| 1072 | |
| 1073 | // USE WITH CARE - THIS MAY DELETE ALL ENTRIES |
| 1074 | async function deleteKeys(keyToDelete) { |
| 1075 | let confirmationMessage = keyToDelete |
| 1076 | ? `This will delete the template with key "${keyToDelete}". Continue?` |
| 1077 | : "This will delete ALL templates. Continue?"; |
| 1078 | if (confirm(confirmationMessage)) { |
| 1079 | return openDB().then(db => { |
| 1080 | let tx = db.transaction("EasyDiffusionSettings", "readwrite"); |
| 1081 | let store = tx.objectStore("EasyDiffusionSettings"); |
| 1082 | return new Promise((resolve, reject) => { |
| 1083 | store.openCursor().onsuccess = function (event) { |
| 1084 | let cursor = event.target.result; |
| 1085 | if (cursor) { |
| 1086 | if (!keyToDelete || cursor.key === keyToDelete) { |
| 1087 | cursor.delete(); |
| 1088 | } |
| 1089 | cursor.continue(); |
| 1090 | } else { |
| 1091 | // refresh the dropdown and resolve |
| 1092 | resolve(); |
| 1093 | } |
| 1094 | }; |
| 1095 | }); |
| 1096 | }); |
| 1097 | } |
| 1098 | } |
| 1099 | |
| 1100 | /** |
| 1101 | * @param {String} Data URL of the image |