Skip to content

Commit

Permalink
Update page title dynamically to improve history
Browse files Browse the repository at this point in the history
  • Loading branch information
mebeim committed Jan 8, 2024
1 parent 964d7ce commit a541d46
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions www/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ async function fetchSyscallTable(arch, bits, abi, tag) {
return await fetchJSON(`db/${arch}/${bits}/${abi}/${tag}/table.json`)
}

function getArchSelectionText() {
return archSelectEl.selectedOptions[0].textContent
}

function getSelection() {
const archOpt = archSelectEl.selectedOptions[0]
const tagOpt = tagSelectEl.selectedOptions[0]
Expand Down Expand Up @@ -456,6 +460,7 @@ async function update(pushHistoryState) {
const selection = getSelection()
const [arch, bits, abi, tag] = selection
const {config, stderr} = db[arch][bits][abi][tag]
const newTitle = `Linux syscall table: ${tag}, ${getArchSelectionText()}`

currentSyscallTable = await fetchSyscallTable(arch, bits, abi, tag)
fillTable(currentSyscallTable, tag)
Expand All @@ -479,12 +484,14 @@ async function update(pushHistoryState) {

if (pushHistoryState) {
if (firstUpdate) {
history.replaceState(selection, '', '/?' + selectionToQueryString(selection))
history.replaceState(selection, newTitle, '/?' + selectionToQueryString(selection))
firstUpdate = false
} else {
history.pushState(selection, '', '/?' + selectionToQueryString(selection))
history.pushState(selection, newTitle, '/?' + selectionToQueryString(selection))
}
}

document.title = newTitle
}

function archSelectChangeHandler(e) {
Expand Down

0 comments on commit a541d46

Please sign in to comment.