Skip to content

Instantly share code, notes, and snippets.

@lovromazgon
Last active February 21, 2019 09:15
Show Gist options
  • Save lovromazgon/1e02018cafa132d0655e8c6850f18e17 to your computer and use it in GitHub Desktop.
Save lovromazgon/1e02018cafa132d0655e8c6850f18e17 to your computer and use it in GitHub Desktop.
Tampermonkey script which changes the background of a column in Github projects if the work in progress limit is exceeded.
// ==UserScript==
// @name Github Projects work in progress limit
// @namespace https://github.com/lovromazgon
// @version 0.4
// @updateURL https://gist.github.com/lovromazgon/1e02018cafa132d0655e8c6850f18e17/raw/github_projects_wip.user.js
// @downloadURL https://gist.github.com/lovromazgon/1e02018cafa132d0655e8c6850f18e17/raw/github_projects_wip.user.js
// @description Changes the background of a column in Github projects if the work in progress limit is exceeded.
// @author Lovro Mažgon
// @match https://github.com/toggl/*/projects/*
// @grant none
// ==/UserScript==
(function(open) {
var urlRegex = /^https:\/\/github.com\/.*\/cards.*$/
XMLHttpRequest.prototype.open = function() {
this.addEventListener("readystatechange", function() {
if (this.readyState == 4 && urlRegex.test(this.responseURL)) {
updateColumnBackgrounds();
}
}, false);
open.apply(this, arguments);
};
updateColumnBackgrounds();
})(XMLHttpRequest.prototype.open);
function updateColumnBackgrounds() {
var titleRegex = /.*\((\d+)\)$/
var projectColumns = document.getElementsByClassName('project-column');
for (var i = 0; i < projectColumns.length; i++) {
var columnTitle = projectColumns[i].getElementsByClassName('js-project-column-name')[0].innerHTML;
var taskCount = projectColumns[i].getElementsByClassName('js-column-card-count')[0].innerHTML;
taskCount = parseInt(taskCount);
var taskLimitMatch = columnTitle.match(titleRegex);
if (taskLimitMatch) {
var taskLimit = parseInt(taskLimitMatch[1]);
if (taskLimit < taskCount) {
projectColumns[i].style.backgroundColor = "#ff8989";
} else {
projectColumns[i].style.backgroundColor = null;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment