Skip to content

Instantly share code, notes, and snippets.

@johnjohndoe
Last active July 30, 2019 15:21
Show Gist options
  • Save johnjohndoe/74a953ff3c51b47d5c86fb7c8da35855 to your computer and use it in GitHub Desktop.
Save johnjohndoe/74a953ff3c51b47d5c86fb7c8da35855 to your computer and use it in GitHub Desktop.
Jazz highlight my tickets.
// ==UserScript==
// @name Jazz highlight my tickets.
// @description Visually highlights rows which belongs to the currently logged-in user.
// @version 2.0.0
// @author Tobias Preuss
// @grant none
// @include https://jazz.example.com/ccm/web/projects/*
// ==/UserScript==
// sleep time expects milliseconds
function sleep (time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
(function(d) {
var backgroundColor = "#c9decc";
// Returns the user name if found, otherwise an empty string.
getUserName = function() {
var userNameNodes = Array.from(document.getElementsByClassName("user-name"));
if (userNameNodes.length < 1) {
return "";
}
return userNameNodes[0].innerText;
};
// Returns the index of the table header column
// which matches the given class name if found,
// otherwise -1.
getTableHeaderColumnIndex = function(table, className) {
var headerColumns = table.tHead.rows[0].cells;
var columnIndex = -1;
for (var index = 0; index < headerColumns.length; index++) {
var columnHeader = headerColumns[index];
var classNames = columnHeader.classList;
if (classNames.contains(className)) {
columnIndex = index;
break;
}
}
// console.log("Column index -> " + columnIndex);
return columnIndex;
};
customizeUserRow = function(row, backgroundColor) {
row.style.background = backgroundColor;
};
// Returns true if the row is assigned by the user, otherwise fa
assignedByUser = function(ownerColumnIndex, userName) {
return function(row) {
var ownerCellText = row.cells[ownerColumnIndex].innerText;
return ownerCellText.search(userName) !== -1;
}
};
// Highlights rows which belong to the current user.
highlightUserRows = function() {
var userName = getUserName();
if (userName === "") {
return;
}
// console.log(userName);
var tables = Array.from(document.getElementsByClassName("queryResultsTable"));
if (tables.length < 1) {
return;
}
var table = tables[0];
var ownerColumnIndex = getTableHeaderColumnIndex(table, "owner");
if (ownerColumnIndex === -1) {
return;
}
Array
.from(table.tBodies[0].rows)
.filter(assignedByUser(ownerColumnIndex, userName))
.forEach((row) => customizeUserRow(row, backgroundColor));
};
sleep(500).then(() => {
highlightUserRows();
});
})(document)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment