Version 2.4.1 release

This commit is contained in:
Maciej Pędzich 2021-02-17 09:05:53 +01:00
parent 42d2a471b5
commit cd7ea8f7ee
3 changed files with 14 additions and 7 deletions

View File

@ -1,5 +1,9 @@
# Changelog # Changelog
## 2.4.1
- Set `inputHistory` in localStorage to a stringified array, rather tan a string of comma-separated values
## 2.4.0 ## 2.4.0
- Persist input history (up to 10 entries) using `localStorage` - Persist input history (up to 10 entries) using `localStorage`

View File

@ -3,7 +3,7 @@ const cmdHistoryElement = document.querySelector('#cmd-history');
const today = new Date(); const today = new Date();
const currentYear = today.getFullYear(); const currentYear = today.getFullYear();
const inputHistory = localStorage.getItem('inputHistory') const inputHistory = localStorage.getItem('inputHistory')
? localStorage.getItem('inputHistory').split(',') ? JSON.parse(localStorage.getItem('inputHistory'))
: []; : [];
let cmdIndex = 0; let cmdIndex = 0;
@ -17,9 +17,9 @@ window.addEventListener('keypress', (evt) => {
if (evt.key === 'Enter' && command.length > 0) { if (evt.key === 'Enter' && command.length > 0) {
const args = split.slice(1); const args = split.slice(1);
const cmdToSave = document.createElement('p'); const cmdToSave = document.createElement('p');
const output = document.createElement('p'); const output = document.createElement('p');
cmdToSave.textContent = `> ${inputText}`; cmdToSave.textContent = `> ${inputText}`;
cmdHistoryElement.append(cmdToSave); 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.`; When not coding, he is probably watching an F1 race, or playing retro video games.`;
break; break;
case 'bgcolor': case 'bgcolor':
const bgcolor = args[0]; const [bgcolor] = args;
document.body.style.backgroundColor = bgcolor; document.body.style.backgroundColor = bgcolor;
break; break;
case 'cls': case 'cls':
cmdHistoryElement.textContent = ''; cmdHistoryElement.textContent = '';
break; break;
case 'color': case 'color':
const color = args[0]; const [color] = args;
document.body.style.color = color; document.body.style.color = color;
input.style.color = color; input.style.color = color;
break; break;
@ -53,7 +53,7 @@ window.addEventListener('keypress', (evt) => {
<a href="mailto:contact@maciejpedzi.ch">contact@maciejpedzi.ch</a>`; <a href="mailto:contact@maciejpedzi.ch">contact@maciejpedzi.ch</a>`;
break; break;
case 'github': case 'github':
output.innerHTML = `If new tab didn't show up, go <a href="https://github.com/maciejpedzich">here</a>`; output.innerHTML = `If a new tab didn't show up, go <a href="https://github.com/maciejpedzich">here</a>`;
window.open('https://github.com/maciejpedzich'); window.open('https://github.com/maciejpedzich');
break; break;
case "'help'": case "'help'":
@ -81,7 +81,10 @@ window.addEventListener('keypress', (evt) => {
} }
inputHistory.unshift(inputText); inputHistory.unshift(inputText);
localStorage.setItem('inputHistory', inputHistory.slice(0, 10).join()); localStorage.setItem(
'inputHistory',
JSON.stringify(inputHistory.slice(0, 10))
);
cmdHistoryElement.append(output); cmdHistoryElement.append(output);
input.value = ''; input.value = '';

View File

@ -12,7 +12,7 @@
</head> </head>
<body> <body>
<div id="header"> <div id="header">
<p>maciejpedzi.ch [Version 2.4.0]</p> <p>maciejpedzi.ch [Version 2.4.1]</p>
<p>(C) Maciej Pedzich <span id="current-year"></span></p> <p>(C) Maciej Pedzich <span id="current-year"></span></p>
<p id="hint">Welcome! Type 'help' for more information</p> <p id="hint">Welcome! Type 'help' for more information</p>
</div> </div>