Spaces:
Sleeping
Sleeping
Create static/script.js
Browse files- static/script.js +78 -0
static/script.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
window.addEventListener("load", function () {
|
| 2 |
+
const levelSelect = document.querySelectorAll("select")[1];
|
| 3 |
+
const outputBox = document.querySelector("textarea[aria-label='📝 Transcription & Correction']");
|
| 4 |
+
const historyContainer = document.querySelector("#history-output");
|
| 5 |
+
|
| 6 |
+
const savedLevel = localStorage.getItem("level");
|
| 7 |
+
if (savedLevel && levelSelect) levelSelect.value = savedLevel;
|
| 8 |
+
|
| 9 |
+
// Crear botón para borrar historial
|
| 10 |
+
const clearBtn = document.createElement("button");
|
| 11 |
+
clearBtn.textContent = "🗑️ Borrar historial";
|
| 12 |
+
clearBtn.style.marginTop = "10px";
|
| 13 |
+
clearBtn.style.padding = "5px 10px";
|
| 14 |
+
clearBtn.style.backgroundColor = "#ffdddd";
|
| 15 |
+
clearBtn.style.border = "1px solid #d33";
|
| 16 |
+
clearBtn.style.cursor = "pointer";
|
| 17 |
+
clearBtn.style.fontWeight = "bold";
|
| 18 |
+
|
| 19 |
+
// Insertar botón después del contenedor principal
|
| 20 |
+
if (historyContainer && historyContainer.parentNode) {
|
| 21 |
+
historyContainer.parentNode.insertBefore(clearBtn, historyContainer.nextSibling);
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
function mostrarCorrecciones(level) {
|
| 25 |
+
const stored = JSON.parse(localStorage.getItem("corrections_by_level") || "{}");
|
| 26 |
+
const frases = stored[level] || [];
|
| 27 |
+
|
| 28 |
+
if (outputBox) {
|
| 29 |
+
const formatted = frases.map((c, i) => `#${i + 1}: ${c}`).join("\n");
|
| 30 |
+
outputBox.placeholder = frases.length
|
| 31 |
+
? `Last 3 corrected for level "${level}":\n${formatted}`
|
| 32 |
+
: `No corrections yet for level "${level}".`;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
if (historyContainer) {
|
| 36 |
+
historyContainer.innerHTML = frases.length
|
| 37 |
+
? `<h4>📚 Últimas correcciones para <b>${level}</b></h4><ul>` +
|
| 38 |
+
frases.map(f => `<li>${f}</li>`).join("") +
|
| 39 |
+
`</ul>`
|
| 40 |
+
: `<h4>📚 No hay correcciones previas para <b>${level}</b></h4>`;
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
const currentLevel = levelSelect?.value || "General";
|
| 45 |
+
mostrarCorrecciones(currentLevel);
|
| 46 |
+
|
| 47 |
+
levelSelect?.addEventListener("change", () => {
|
| 48 |
+
localStorage.setItem("level", levelSelect.value);
|
| 49 |
+
mostrarCorrecciones(levelSelect.value);
|
| 50 |
+
});
|
| 51 |
+
|
| 52 |
+
const observer = new MutationObserver(() => {
|
| 53 |
+
const newText = outputBox?.value;
|
| 54 |
+
if (!newText) return;
|
| 55 |
+
|
| 56 |
+
const match = newText.match(/✅ \*\*Corrected:\*\* (.+?)\n/);
|
| 57 |
+
if (match && match[1]) {
|
| 58 |
+
const corrected = match[1];
|
| 59 |
+
const currentLevel = levelSelect?.value || "General";
|
| 60 |
+
|
| 61 |
+
const stored = JSON.parse(localStorage.getItem("corrections_by_level") || "{}");
|
| 62 |
+
stored[currentLevel] = [corrected, ...(stored[currentLevel] || [])].slice(0, 3);
|
| 63 |
+
localStorage.setItem("corrections_by_level", JSON.stringify(stored));
|
| 64 |
+
mostrarCorrecciones(currentLevel);
|
| 65 |
+
}
|
| 66 |
+
});
|
| 67 |
+
|
| 68 |
+
if (outputBox) {
|
| 69 |
+
observer.observe(outputBox, { childList: true, subtree: true });
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
clearBtn.addEventListener("click", () => {
|
| 73 |
+
if (confirm("¿Estás seguro de que quieres borrar todo el historial de correcciones?")) {
|
| 74 |
+
localStorage.removeItem("corrections_by_level");
|
| 75 |
+
mostrarCorrecciones(levelSelect?.value || "General");
|
| 76 |
+
}
|
| 77 |
+
});
|
| 78 |
+
});
|