1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| let bits = document.getElementsByClassName("bit") let time
function setNext(node, value) { if (node.lastChild.innerText != value) { let newBit = document.createElement("div") newBit.innerText = value node.appendChild(newBit) Array.from(node.getElementsByTagName("div")).slice(0, -2).forEach(Element => { Element.setAttribute("remove", "") }) } }
function setTime() { let date = new Date(); time = date.getHours().toString().padStart(2, "0") + date.getMinutes().toString().padStart(2, "0") + date.getSeconds().toString().padStart(2, "0")
Array.from(bits).forEach((bit, index) => { setNext(bits[index], time.slice(index, index + 1)) Array.from(bit.getElementsByTagName("div")).slice(0, -3).forEach(Element => { Element.remove() }) }) } setInterval(setTime, 100)
|