diff --git a/takhta.html b/takhta.html index fb2e043..e94da99 100644 --- a/takhta.html +++ b/takhta.html @@ -74,6 +74,9 @@ .undone { text-decoration: line-through; } + .numentry { + white-space: pre-wrap; + } @@ -277,6 +280,26 @@ // List the move let listElement = document.createElement('li'); + + if(moveHistory.length % 2 === 1) { + let padding = Math.floor(Math.log10((moveHistory.length / 2) + 1)); + let moveList = document.getElementsByClassName('numentry'); + + for(let next = 0; next < moveList.length; next += 1) { + let digits = Math.floor(Math.log10(next + 1)); + + if(digits < padding) { + moveList[next].innerText = `${next + 1}. `.padStart(padding + digits + 3, " "); + } + } + + let numEntry = document.createElement('span'); + + numEntry.classList.add('numentry'); + numEntry.innerText = `${parseInt(moveHistory.length / 2) + 1}. `; + listElement.appendChild(numEntry); + } + listElement.appendChild(document.createTextNode(move)); movelist.appendChild(listElement);