Last active
December 6, 2022 07:03
-
-
Save joelamos/420a6186599cc0abdcc41a7620580afc to your computer and use it in GitHub Desktop.
Colorizes Azure DevOps board tiles based on assignee. To be used in conjunction with a browser extension that runs JavaScript on page load
This file contains 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
const colors = { | |
red: { lightTheme: '#ffb2b2', darkTheme: '#723333', persons: ['Kevin', 'Brittany'] }, | |
blue: { lightTheme: '#9fbeec', darkTheme: '#355078', persons: ['Bryce', 'Kyle'] }, | |
green: { lightTheme: '#ccf2cc', darkTheme: '#336245', persons: ['Joel', 'Creed'] }, | |
purple: { lightTheme: '#d8b0d8', darkTheme: '#5d365d', persons: ['Ardalan', 'David'] }, | |
pink: { lightTheme: '#ffe9e9', darkTheme: '#b97777', persons: ['James'] }, | |
yellow: { lightTheme: '#ffe49f', darkTheme: '#d99c00', persons: ['Ethan', 'Tom'] }, | |
turquoise: { lightTheme: '#a3e4dd', darkTheme: '#009989', persons: ['Mark', 'Creed'] }, | |
tan: { lightTheme: '#c0b79d', darkTheme: '#948661', persons: ['Sonali', 'Thomas'] }, | |
brown: { lightTheme: '#d0b089', darkTheme: '#72522c', persons: ['Adam', 'Robin'] }, | |
gray: { lightTheme: '#e4e4e4', darkTheme: '#454545', persons: ['Arun', 'Naina'] }, | |
}; | |
const colorNameByPerson = Object.keys(colors).reduce((obj, colorName) => { | |
colors[colorName].persons.forEach(person => obj[person] = colorName); | |
return obj; | |
}, {}); | |
const tileObserver = new MutationObserver(mutations => colorizeTile(mutations[0].target)); | |
const controlField = "System.AssignedTo"; | |
const observedTiles = []; | |
let themeProperty; | |
window.addEventListener('load', () => { | |
themeProperty = getThemeProperty(); | |
setInterval(() => $('.board-tile').each((i, tile) => { | |
colorizeTile(tile); | |
observeTileIfNew(tile); | |
}), 200); | |
}); | |
function colorizeTile(tile) { | |
const colorName = getTileColorName(tile); | |
if (!colorName) return; | |
colorValue = colors[colorName][themeProperty]; | |
$('.board-tile-content-container', tile).css('background-color', colorValue); | |
} | |
function getTileColorName(tile) { | |
const assignee = $(`[field="${controlField}"]`, tile).text(); | |
const assigneeKey = Object.keys(colorNameByPerson).filter(person => assignee.includes(person))[0]; | |
if (assigneeKey) return colorNameByPerson[assigneeKey]; | |
} | |
function observeTileIfNew(tile) { | |
if (observedTiles.includes(tile)) return; | |
tileObserver.observe(tile, { childList: true }); | |
observedTiles.push(tile); | |
} | |
function getThemeProperty() { | |
const headerColor = $('.region-header').css('background-color'); | |
if (headerColor === 'rgb(32, 31, 30)') return 'darkTheme'; | |
if (headerColor === 'rgb(255, 255, 255)') return 'lightTheme'; | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment