Last active
February 21, 2019 09:15
-
-
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.
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
// ==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