110 lines
3.3 KiB
JavaScript
110 lines
3.3 KiB
JavaScript
|
||
//MAIN
|
||
document.addEventListener("DOMContentLoaded", insertValueMainButton);
|
||
|
||
function insertValueMainButton () {
|
||
const inputBox = document.getElementById("inputBox");
|
||
const testButton = document.getElementById("testButton");
|
||
const outputArea = document.getElementById("outputArea");
|
||
|
||
testButton.addEventListener("click", EnterWord);
|
||
}
|
||
|
||
function EnterWord() {
|
||
const userInput = inputBox.value.trim().toLowerCase(); // Ignoriere Groß-/Kleinschreibung
|
||
|
||
if (!userInput) {
|
||
outputArea.textContent = "🔎 Bitte gib einen Hinweis ein!";
|
||
return;
|
||
}
|
||
|
||
// Lade das Dictionary aus dem LocalStorage
|
||
const storedData = JSON.parse(localStorage.getItem("hinweisDict")) || {};
|
||
|
||
// Finde passenden Key (case-insensitive Vergleich)
|
||
let matchedKey = null;
|
||
for (const key in storedData) {
|
||
if (key.toLowerCase() === userInput) {
|
||
matchedKey = key;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (matchedKey) {
|
||
outputArea.textContent = `✅ "${matchedKey}" gefunden: ${storedData[matchedKey]}`;
|
||
} else {
|
||
outputArea.textContent = `❌ Kein Hinweis gefunden für "${userInput}".`;
|
||
}
|
||
}
|
||
|
||
//INDEX
|
||
document.addEventListener("keydown", function (event) {
|
||
if (event.ctrlKey && (event.key === "ä" || event.code === "Quote")) {
|
||
//event.preventDefault();
|
||
//Name: mainView
|
||
//Name: inputView
|
||
const mv = document.getElementById("mainView");
|
||
if (mv.style.visibility === "visible" || mv.style.visibility === "") {
|
||
mv.style.visibility = "hidden";
|
||
} else {
|
||
mv.style.visibility = "visible";
|
||
}
|
||
const el = document.getElementById("inputView");
|
||
if (el.style.visibility === "visible" || el.style.visibility === "") {
|
||
el.style.visibility = "hidden";
|
||
} else {
|
||
el.style.visibility = "visible";
|
||
}
|
||
|
||
}
|
||
else if (event.key === "Enter") {
|
||
event.preventDefault(); // Optional: verhindert z. B. Form-Submit
|
||
const mv = document.getElementById("mainView");
|
||
if (mv.style.visibility === "visible" || mv.style.visibility === "") {
|
||
EnterWord();
|
||
} else {
|
||
saveEntry();
|
||
}
|
||
|
||
}
|
||
}, false);
|
||
|
||
//INPUT
|
||
// Daten laden und anzeigen
|
||
function loadDictionary() {
|
||
const entriesDiv = document.getElementById("entries");
|
||
entriesDiv.innerHTML = "";
|
||
|
||
const data = JSON.parse(localStorage.getItem("hinweisDict")) || {};
|
||
|
||
for (const key in data) {
|
||
const div = document.createElement("div");
|
||
div.className = "entry";
|
||
div.innerHTML = `<span class="key">${key}</span>: <span class="value">${data[key]}</span>`;
|
||
entriesDiv.appendChild(div);
|
||
}
|
||
}
|
||
|
||
// Eintrag speichern
|
||
function saveEntry() {
|
||
const key = document.getElementById("inputKey").value.trim();
|
||
const value = document.getElementById("inputValue").value.trim();
|
||
|
||
if (key === "" || value === "") {
|
||
alert("Beide Felder müssen ausgefüllt sein.");
|
||
return;
|
||
}
|
||
|
||
const data = JSON.parse(localStorage.getItem("hinweisDict")) || {};
|
||
data[key] = value;
|
||
localStorage.setItem("hinweisDict", JSON.stringify(data));
|
||
|
||
document.getElementById("inputKey").value = "";
|
||
document.getElementById("inputValue").value = "";
|
||
loadDictionary();
|
||
}
|
||
|
||
// Beim Laden anzeigen
|
||
window.onload = loadDictionary;
|
||
|