diff --git a/public/js/home.js b/public/js/home.js new file mode 100644 index 0000000..38041bb --- /dev/null +++ b/public/js/home.js @@ -0,0 +1,26 @@ +const now = new Date() +const tomorrow = now.getDay() + 1 +if (tomorrow >= 1 && tomorrow <= 5){ + document.querySelectorAll(`th:nth-child(${tomorrow + 1})`).forEach(cell => { + cell.style.fontWeight = 900 + cell.classList.add('table-active') + }) + document.querySelectorAll(`tr td:nth-child(${tomorrow + 1})`).forEach(cell => { + cell.style.fontWeight = 900 + cell.classList.add('table-warning') + }) +} + +filesize.partial({base: 2, standard: "jedec"}) +const zhao = io('ws://zhao', { path: '/status/socket.io', }) +zhao.on('status', (status) => { + zhao_temp.innerText = status.cpu.temperature.toFixed(2) + zhao_cpu.innerText = status.cpu.load.toFixed(2) + zhao_mem.innerText = filesize(status.memory.available) +}) +const pi = io('ws://pi', { path: '/status/socket.io', }) +pi.on('status', (status) => { + pi_temp.innerText = status.cpu.temperature.toFixed(2) + pi_cpu.innerText = status.cpu.load.toFixed(2) + pi_mem.innerText = filesize(status.memory.available) +}) diff --git a/views/home.pug b/views/home.pug index 3cb97a8..1e0f665 100644 --- a/views/home.pug +++ b/views/home.pug @@ -123,18 +123,6 @@ block main td 英语 td 劳动 td 音乐 - script. - const now = new Date() - const tomorrow = now.getDay() + 1 - if (tomorrow >= 1 && tomorrow <= 5) - document.querySelectorAll(`th:nth-child(${tomorrow + 1})`).forEach(cell => { - cell.style.fontWeight = 900 - cell.classList.add('table-active') - }) - document.querySelectorAll(`tr td:nth-child(${tomorrow + 1})`).forEach(cell => { - cell.style.fontWeight = 900 - cell.classList.add('table-warning') - }) .container .row.row-cols-md-2.gy-3 @@ -178,19 +166,6 @@ block main p.card-text | 内存剩余: code#pi_mem - script(src="/socket.io/socket.io.min.js") - script(src="/js/filesize.min.js") - script. - filesize.partial({base: 2, standard: "jedec"}) - const zhao = io('ws://zhao', { path: '/status/socket.io', }) - zhao.on('status', (status) => { - zhao_temp.innerText = status.cpu.temperature.toFixed(2) - zhao_cpu.innerText = status.cpu.load.toFixed(2) - zhao_mem.innerText = filesize(status.memory.available) - }) - const pi = io('ws://pi', { path: '/status/socket.io', }) - pi.on('status', (status) => { - pi_temp.innerText = status.cpu.temperature.toFixed(2) - pi_cpu.innerText = status.cpu.load.toFixed(2) - pi_mem.innerText = filesize(status.memory.available) - }) + script(src="/socket.io/socket.io.min.js", defer) + script(src="/js/filesize.min.js", defer) + script(src="/js/home.js", defer)