diff --git a/js/collection.js b/js/collection.js index 2f8e92e..defc396 100644 --- a/js/collection.js +++ b/js/collection.js @@ -43,6 +43,7 @@ export function addToHistory(hsl) { export function addColorToSchema(hsl) { const name = prompt('Schema-Name (leer = letztes Schema):'); + if (name === null) return; // user pressed Cancel — do nothing const data = load(); if (name) { const existing = data.schemata.find(s => s.name === name); @@ -83,10 +84,14 @@ export function deleteSchema(name) { export function exportCollection() { const data = load(); const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' }); + const url = URL.createObjectURL(blob); const a = document.createElement('a'); - a.href = URL.createObjectURL(blob); + a.href = url; a.download = 'farbhelfer-sammlung.json'; + document.body.appendChild(a); a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(url); } export function importCollection() { @@ -109,6 +114,11 @@ export function importCollection() { (imported.schemata || []).forEach(s => { if (!existingSchemaNames.has(s.name)) data.schemata.push(s); }); + const existingHistHexes = new Set(data.history.map(hslToHex)); + (imported.history || []).forEach(hsl => { + if (!existingHistHexes.has(hslToHex(hsl))) data.history.push(hsl); + }); + if (data.history.length > 20) data.history = data.history.slice(0, 20); save(data); renderSammlung(); alert('Import erfolgreich.');