diff --git a/content.js b/content.js index aa4f6a4..f7daead 100644 --- a/content.js +++ b/content.js @@ -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") } diff --git a/style.css b/style.css index 25637f8..14a881a 100644 --- a/style.css +++ b/style.css @@ -9,7 +9,8 @@ button.ripper-btn { color: #fff; font: inherit; font-size: 0.85em; - line-height: 1.4; + font-weight: bold; + line-height: 1.1; cursor: pointer; }