';
downloadFile(html, 'corrected-text.doc', 'application/msword');
}function downloadFile(content, filename, type) {
const blob = new Blob([content], { type: type });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}// Undo function
function undo() {
if (history.length > 0) {
const last = history.pop();
textInput.value = last;
processText();
} else {
alert('No history available');
}
}// Clear function
function clear() {
textInput.value = '';
outputSection.classList.remove('show');
rulesSection.classList.remove('show');
history = [];
}// Reset function
function reset() {
clear();
textInput.value = 'I went to the store to buy apples oranges and bananas. However I forgot my wallet so I had to go back home. When I returned the store was closed which was very disappointing.';
}// PWA installation
function installApp() {
alert('Use your browser\'s "Add to Home Screen" feature to install this app.');
}// Event listeners
processBtn.addEventListener('click', processText);
rulesBtn.addEventListener('click', toggleRules);
undoBtn.addEventListener('click', undo);
clearBtn.addEventListener('click', clear);
copyBtn.addEventListener('click', copyText);
txtBtn.addEventListener('click', downloadTxt);
docBtn.addEventListener('click', downloadDoc);
installBtn.addEventListener('click', installApp);
footerInstallBtn.addEventListener('click', installApp);
resetBtn.addEventListener('click', reset);// Auto-process on load
setTimeout(processText, 1000);
});