Add numbered moves to each turn sequence

This commit is contained in:
Nick Chambers 2021-01-10 15:44:07 -06:00
parent ca2cb19da7
commit 750c395a4f
1 changed files with 23 additions and 0 deletions

View File

@ -74,6 +74,9 @@
.undone {
text-decoration: line-through;
}
.numentry {
white-space: pre-wrap;
}
</style>
</head>
<body>
@ -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);