Greasemonkey Script to Restore Mantis Ticket Colours

Mantis, the bug tracking software, changed the style of each ticket’s background during an update. This is a Greasemonkey script to re-introduce strong background colours so you can quickly see the status of a ticket.

You probably don’t want to run this on every page you visit, so you can add a // @match http://www.example.com/* into the top comment.

// ==UserScript==
// @name     MantisColours
// @version  1
// @grant    none
// ==/UserScript==

var styles = [
  {10: 'fed4d4'}, // new
  {40: 'fff494'}, // confirmed
  {50: 'd7eaff'}, // assigned
  {80: 'caf5a0'}, // resolved
  {90: 'c2c2c2'}, // closed
];

for (var i=0; i<styles.length; i++) {
  var colourClass = '.status-' + Object.keys(styles[i])[0] +'-color';
  document.querySelectorAll(colourClass).forEach( function(el) {

    // Hide the original colour indicator
    el.style.display = 'none';

    // Set all tds in this row to have the correct bg colour
    el.parentNode.parentNode.parentNode.querySelectorAll('td').forEach( function(tdEl) {
      var colourHex = Object.values(styles[i])[0];
      tdEl.style.backgroundColor = '#' + colourHex;
    });
  });
}

console.log('Mantis Colour Script has Run');