diff --git a/CHANGELOG.md b/CHANGELOG.md index f9cbfb0..c1e764d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 2.4.1 + +- Set `inputHistory` in localStorage to a stringified array, rather tan a string of comma-separated values + ## 2.4.0 - Persist input history (up to 10 entries) using `localStorage` diff --git a/assets/js/script.js b/assets/js/script.js index d17d04c..1f041e5 100644 --- a/assets/js/script.js +++ b/assets/js/script.js @@ -3,7 +3,7 @@ const cmdHistoryElement = document.querySelector('#cmd-history'); const today = new Date(); const currentYear = today.getFullYear(); const inputHistory = localStorage.getItem('inputHistory') - ? localStorage.getItem('inputHistory').split(',') + ? JSON.parse(localStorage.getItem('inputHistory')) : []; let cmdIndex = 0; @@ -17,9 +17,9 @@ window.addEventListener('keypress', (evt) => { if (evt.key === 'Enter' && command.length > 0) { const args = split.slice(1); - const cmdToSave = document.createElement('p'); const output = document.createElement('p'); + cmdToSave.textContent = `> ${inputText}`; cmdHistoryElement.append(cmdToSave); @@ -37,14 +37,14 @@ window.addEventListener('keypress', (evt) => { When not coding, he is probably watching an F1 race, or playing retro video games.`; break; case 'bgcolor': - const bgcolor = args[0]; + const [bgcolor] = args; document.body.style.backgroundColor = bgcolor; break; case 'cls': cmdHistoryElement.textContent = ''; break; case 'color': - const color = args[0]; + const [color] = args; document.body.style.color = color; input.style.color = color; break; @@ -53,7 +53,7 @@ window.addEventListener('keypress', (evt) => { contact@maciejpedzi.ch`; break; case 'github': - output.innerHTML = `If new tab didn't show up, go here`; + output.innerHTML = `If a new tab didn't show up, go here`; window.open('https://github.com/maciejpedzich'); break; case "'help'": @@ -81,7 +81,10 @@ window.addEventListener('keypress', (evt) => { } inputHistory.unshift(inputText); - localStorage.setItem('inputHistory', inputHistory.slice(0, 10).join()); + localStorage.setItem( + 'inputHistory', + JSON.stringify(inputHistory.slice(0, 10)) + ); cmdHistoryElement.append(output); input.value = ''; diff --git a/index.html b/index.html index 63a4620..b577258 100644 --- a/index.html +++ b/index.html @@ -12,7 +12,7 @@