make button injection less brittle in list

This commit is contained in:
gapato 2026-06-12 14:51:29 +02:00
commit 7354709b78
2 changed files with 18 additions and 13 deletions

View file

@ -630,30 +630,28 @@ function createRipButton(aid) {
function installTable(tableBody) {
if (tableBody == null) {
console.log("could not install button")
return
return false
}
tableBody.querySelectorAll("tr").forEach((tr) => {
if (tr.querySelector(".ripper-btn") != null) return;
if (tr.querySelector(".ripper-btn") != null) return true;
const nameTd = tr.querySelector(".column-name")
const link = nameTd?.querySelector("a")
const href = link?.href
if (href == null) {
console.log("could not install button")
return
return false
}
const match = href.match(/^https:\/\/personal\.uni-graz\.at\/#\/job-procedures\/record\/([0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12})/)
if (match == null) {
console.log("could not install button")
return
return false
}
const aid = match[1]
const actionMenu = tableBody.querySelector("scrm-line-action-menu")
if (actionMenu == null) {
console.log("could not install button")
return
return false
}
console.log("rip button installed")
actionMenu.append(createRipButton(aid))
return true
})
}
@ -671,10 +669,16 @@ function install() {
titleTag.append(" (", createRipButton(getApplicationId()), ")")
} else if (window.location.hash === "#/job-procedures/list") {
/* procedure list page, add the button to each row */
setTimeout(() => {
let intervalId = -1;
let tries = 0;
const intervalLoop = () => {
const tableBody = document.querySelector("scrm-table")?.querySelector("tbody")
installTable(tableBody)
}, 1000)
tries += 1
if (installTable(tableBody) || tries > 20) {
clearInterval(intervalId)
}
}
intervalId = setInterval(intervalLoop, 100)
} else {
console.log("could not install button")
}