make button injection less brittle in list
This commit is contained in:
parent
52a20a0b21
commit
7354709b78
2 changed files with 18 additions and 13 deletions
28
content.js
28
content.js
|
|
@ -630,30 +630,28 @@ function createRipButton(aid) {
|
||||||
|
|
||||||
function installTable(tableBody) {
|
function installTable(tableBody) {
|
||||||
if (tableBody == null) {
|
if (tableBody == null) {
|
||||||
console.log("could not install button")
|
return false
|
||||||
return
|
|
||||||
}
|
}
|
||||||
tableBody.querySelectorAll("tr").forEach((tr) => {
|
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 nameTd = tr.querySelector(".column-name")
|
||||||
const link = nameTd?.querySelector("a")
|
const link = nameTd?.querySelector("a")
|
||||||
const href = link?.href
|
const href = link?.href
|
||||||
if (href == null) {
|
if (href == null) {
|
||||||
console.log("could not install button")
|
return false
|
||||||
return
|
|
||||||
}
|
}
|
||||||
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})/)
|
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) {
|
if (match == null) {
|
||||||
console.log("could not install button")
|
return false
|
||||||
return
|
|
||||||
}
|
}
|
||||||
const aid = match[1]
|
const aid = match[1]
|
||||||
const actionMenu = tableBody.querySelector("scrm-line-action-menu")
|
const actionMenu = tableBody.querySelector("scrm-line-action-menu")
|
||||||
if (actionMenu == null) {
|
if (actionMenu == null) {
|
||||||
console.log("could not install button")
|
return false
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
console.log("rip button installed")
|
||||||
actionMenu.append(createRipButton(aid))
|
actionMenu.append(createRipButton(aid))
|
||||||
|
return true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -671,10 +669,16 @@ function install() {
|
||||||
titleTag.append(" (", createRipButton(getApplicationId()), ")")
|
titleTag.append(" (", createRipButton(getApplicationId()), ")")
|
||||||
} else if (window.location.hash === "#/job-procedures/list") {
|
} else if (window.location.hash === "#/job-procedures/list") {
|
||||||
/* procedure list page, add the button to each row */
|
/* 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")
|
const tableBody = document.querySelector("scrm-table")?.querySelector("tbody")
|
||||||
installTable(tableBody)
|
tries += 1
|
||||||
}, 1000)
|
if (installTable(tableBody) || tries > 20) {
|
||||||
|
clearInterval(intervalId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
intervalId = setInterval(intervalLoop, 100)
|
||||||
} else {
|
} else {
|
||||||
console.log("could not install button")
|
console.log("could not install button")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,8 @@ button.ripper-btn {
|
||||||
color: #fff;
|
color: #fff;
|
||||||
font: inherit;
|
font: inherit;
|
||||||
font-size: 0.85em;
|
font-size: 0.85em;
|
||||||
line-height: 1.4;
|
font-weight: bold;
|
||||||
|
line-height: 1.1;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue