diff --git a/script.js b/script.js index 7efd007..9a92bf4 100644 --- a/script.js +++ b/script.js @@ -89,7 +89,7 @@ document.getElementById('insertQuote').addEventListener('click', function () { document.getElementById('insertUrl').addEventListener('click', function () { const url = document.getElementById('urlInput').value; const linkText = document.getElementById('urlText').value; - const insertion = `[url=${url}] ${linkText} [/url]`; + const insertion = `[url=${url}]${linkText}[/url]`; const beforeSelection = editor.value.substring(0, editor.selectionStart); const afterSelection = editor.value.substring(editor.selectionEnd, editor.value.length); editor.value = beforeSelection + insertion + afterSelection; @@ -157,3 +157,30 @@ editor.addEventListener('keydown', function (e) { } } }); + + +/* LocalStorage */ + +// Save to localStorage +function saveTextAsLocalStorage() { + const text = editor.value; + localStorage.setItem("markupText", text); +} + +// Load from localStorage +function loadTextFromLocalStorage() { + const savedText = localStorage.getItem("markupText"); + if (savedText) { + editor.value = savedText; + updatePreview(); + } +} + +// Event listeners +editor.addEventListener('input', function () { + saveTextAsLocalStorage(); +}); + +document.addEventListener('DOMContentLoaded', (event) => { + loadTextFromLocalStorage(); +});