Last active
October 11, 2020 18:01
-
-
Save bigethan/034d09974dd7816a3bc76fd1ccc5615c to your computer and use it in GitHub Desktop.
Adds table filtering to the sidekiq busy jobs list and toggles the visibility of the processes table. To install click the `Raw` button and your userscript extension will take it from there.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Sidekiq BusyJob Helper | |
// @namespace http://bigethan.com/ | |
// @version 0.1 | |
// @description On Sidekiq's UI fro busy jobs: Toggles the workers table and adds a way to filter the busy jobs table | |
// @author bigethan | |
// @match https://*/sidekiq/busy | |
// @grant none | |
// ==/UserScript== | |
(function (document) { | |
"use strict"; | |
let searchInput = document.createElement("input"); | |
searchInput.setAttribute("type", "text"); | |
searchInput.setAttribute("id", "job_search"); | |
searchInput.setAttribute("placeholder", "Filter Listing"); | |
searchInput.addEventListener("input", filterTable); | |
searchInput.style.verticalAlign = "text-bottom"; | |
searchInput.style.marginLeft = "1em"; | |
let jobsXpath = "//h3[contains(text(),'Jobs')]"; | |
let jobsElement = document.evaluate( | |
jobsXpath, | |
document, | |
null, | |
XPathResult.FIRST_ORDERED_NODE_TYPE, | |
null | |
).singleNodeValue; | |
jobsElement.parentElement.appendChild(searchInput); | |
jobsElement.style.display = "inline-block"; | |
function filterTable() { | |
const filter = document.querySelector("#job_search").value.toUpperCase(); | |
const trs = document.querySelectorAll(".table_container .workers tbody tr"); | |
trs.forEach( | |
(tr) => | |
(tr.style.display = [...tr.children].find((td) => | |
td.innerHTML.toUpperCase().includes(filter) | |
) | |
? "" | |
: "none") | |
); | |
} | |
let processXpath = "//h3[contains(text(),'Processes')]"; | |
let processesElement = document.evaluate( | |
processXpath, | |
document, | |
null, | |
XPathResult.FIRST_ORDERED_NODE_TYPE, | |
null | |
).singleNodeValue; | |
let small = document.createElement("small"); | |
let text = document.createTextNode(" (Click to show/hide)"); | |
small.appendChild(text); | |
processesElement.appendChild(small); | |
processesElement.addEventListener("click", toggleTable); | |
toggleTable(); | |
function toggleTable() { | |
const tbody = document.querySelector(".table_container .processes tbody"); | |
if (tbody.offsetParent === null) { | |
tbody.style.display = "table-row-group"; | |
} else { | |
tbody.style.display = "none"; | |
} | |
} | |
})(document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment