diff options
Diffstat (limited to 'cgit.js')
| -rw-r--r-- | cgit.js | 86 |
1 files changed, 86 insertions, 0 deletions
@@ -0,0 +1,86 @@ +/* This does client-side modifications which should probably be implemented on + * HTML generation, inside cgit. But they aren't (shouldn't be) very heavy or + * slow, so it's probably ok. + */ + +// Proper device scaling +const viewport = document.createElement("meta"); +viewport.id = "viewport"; +viewport.name = "viewport"; +viewport.content = "width=device-width initial-scale=1"; +document.head.appendChild(viewport); + +// 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 + + // 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 + } + } + + // 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 + } + } +} + +// 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] + + 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] + + tabs.insertBefore(tree, refs) + tabs.insertBefore(log, refs) + + summary.innerText = 'Summary' + tree.innerText = 'Files' + log.innerText = 'Commits' +} |
