diff options
| author | Syndamia <kamen@syndamia.com> | 2026-03-21 17:01:35 +0200 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2026-03-21 17:01:35 +0200 |
| commit | 505314c50fafa76f2c465d3d012e81cc41c80f52 (patch) | |
| tree | b63b1c6930df3a97c74cd9f6158ab768bb0bcfc1 /cgit.js | |
| parent | df495cc208d827bb6c0905d2ebd08412396fcdb3 (diff) | |
| download | cgit_theme-505314c50fafa76f2c465d3d012e81cc41c80f52.tar cgit_theme-505314c50fafa76f2c465d3d012e81cc41c80f52.tar.gz cgit_theme-505314c50fafa76f2c465d3d012e81cc41c80f52.zip | |
fix(cgit.js): Execute most logic when document has loaded
Diffstat (limited to 'cgit.js')
| -rw-r--r-- | cgit.js | 122 |
1 files changed, 62 insertions, 60 deletions
@@ -10,77 +10,79 @@ viewport.name = "viewport"; viewport.content = "width=device-width initial-scale=1"; document.head.appendChild(viewport); -// Edit file tree -const list = document.getElementsByClassName('list')[0] +document.addEventListener("DOMContentLoaded", function(){ + // Edit file tree + const list = document.getElementsByClassName('list')[0] -if (list !== undefined && list.summary === "tree listing") { - const table = list.children[0] - const rows = table.children + if (list !== undefined && list.summary === "tree listing") { + const table = list.children[0] + const rows = table.children - // Reorder directories (and submodules) before files - var lastDir = 1 - for (let i = 1; i < rows.length; ++i) { - if (!rows[i].children[0].innerText.startsWith('-')) { - if (i > lastDir) { - table.insertBefore(rows[i], rows[lastDir]) + // Reorder directories (and submodules) before files + var lastDir = 1 + for (let i = 1; i < rows.length; ++i) { + if (!rows[i].children[0].innerText.startsWith('-')) { + if (i > lastDir) { + table.insertBefore(rows[i], rows[lastDir]) + } + ++lastDir } - ++lastDir } - } - // Human-readable size format - for (const row of rows) { - if (row.children[2].classList.contains('ls-size')) { - let size = row.children[2].innerText - if (size < 1024) { - size += ' B' - } - else if (size < 1048576) { - size = (size / 1024).toFixed(1) + ' KiB' - } - else if (size < 1073741824) { - size = (size / 1048576).toFixed(1) + ' MiB' + // Human-readable size format + for (const row of rows) { + if (row.children[2].classList.contains('ls-size')) { + let size = row.children[2].innerText + if (size < 1024) { + size += ' B' + } + else if (size < 1048576) { + size = (size / 1024).toFixed(1) + ' KiB' + } + else if (size < 1073741824) { + size = (size / 1048576).toFixed(1) + ' MiB' + } + else { + size = (size / 1073741824).toFixed(1) + ' GiB' + } + row.children[2].innerText = size } - else { - size = (size / 1073741824).toFixed(1) + ' GiB' - } - row.children[2].innerText = size } } -} -// Edit the tabs -const tabs = document.getElementsByClassName('tabs')[0].children[0].children[0].children[0] + // Edit the tabs + const tabs = document.getElementsByClassName('tabs')[0].children[0].children[0].children[0] -if (tabs !== undefined && tabs.children.length === 7) { - const about = tabs.children[0] - const summary = tabs.children[1] - const refs = tabs.children[2] - const log = tabs.children[3] - const tree = tabs.children[4] - const commit = tabs.children[5] - const diff = tabs.children[6] + if (tabs !== undefined && tabs.children.length === 7) { + const about = tabs.children[0] + const summary = tabs.children[1] + const refs = tabs.children[2] + const log = tabs.children[3] + const tree = tabs.children[4] + const commit = tabs.children[5] + const diff = tabs.children[6] - tabs.insertBefore(tree, refs) - tabs.insertBefore(log, refs) + tabs.insertBefore(tree, refs) + tabs.insertBefore(log, refs) - about.innerText = 'README' - summary.innerText = 'Summary' - tree.innerText = 'Files' - log.innerText = 'Commits' -} -else if (tabs !== undefined && tabs.children.length === 6) { - const summary = tabs.children[0] - const refs = tabs.children[1] - const log = tabs.children[2] - const tree = tabs.children[3] - const commit = tabs.children[4] - const diff = tabs.children[5] + about.innerText = 'README' + summary.innerText = 'Summary' + tree.innerText = 'Files' + log.innerText = 'Commits' + } + else if (tabs !== undefined && tabs.children.length === 6) { + const summary = tabs.children[0] + const refs = tabs.children[1] + const log = tabs.children[2] + const tree = tabs.children[3] + const commit = tabs.children[4] + const diff = tabs.children[5] - tabs.insertBefore(tree, refs) - tabs.insertBefore(log, refs) + tabs.insertBefore(tree, refs) + tabs.insertBefore(log, refs) - summary.innerText = 'Summary' - tree.innerText = 'Files' - log.innerText = 'Commits' -} + summary.innerText = 'Summary' + tree.innerText = 'Files' + log.innerText = 'Commits' + } +}); |
