Skip to content

Instantly share code, notes, and snippets.

@jphastings
Last active October 19, 2015 12:54
Show Gist options
  • Save jphastings/fe94963116708d3755e5 to your computer and use it in GitHub Desktop.
Save jphastings/fe94963116708d3755e5 to your computer and use it in GitHub Desktop.
Simplify ZenHub
// ==UserScript==
// @name Simplify ZenHub
// @namespace https://deliveroo.co.uk/
// @version 0.2.1
// @description ZenHub has lots of info on screen, sometimes too much to see what's going on at a glance. This simplifies things :)
// @author JP Hastings-Spital
// @match https://github.com/*
// @grant none
// ==/UserScript==
/* jshint -W097 */
'use strict';
(function() {
var mod = {
attach: function () {
if (mod.isAttached) return;
$('.pagehead.repohead').hide();
(function() {
function fixHeight() {
var calculatedHeight = $('.zh-board-wrapper').outerHeight() + $('.pagehead.repohead').outerHeight() + 20;
$('.zh-board-wrapper').css('height', calculatedHeight);
mod._replaceEstimates();
}
$(window).on('resize', fixHeight);
fixHeight();
})();
mod._zenHubLoadedWaiter = setInterval(mod._zenHubLoadedCheck, 500);
mod.isAttached = true;
},
detach: function () {
$(window).off('resize');
$('.zh-pipeline-issue-repo, .pagehead.repohead').show();
$('<br />').insertAfter('.zh-pipeline-issue-number');
$(window).trigger('resize');
$('#simplifyZenhub').remove();
clearInterval(mod._zenHubLoadedWaiter);
mod._zenHubLoadedWaiter = null;
mod.isAttached = false;
},
check: function () { return window.location.hash; },
matches: 'boards',
isAttached: false,
_zenHubLoadedWaiter: null,
_zenHubLoadedComplete: function() {
$('.zh-pipeline-issue-repo').hide();
$('.zh-pipeline-issue-number').next('br').remove();
mod._replaceEstimates();
},
_zenHubLoadedCheck: function () {
var unhiddenTitles = $('.zh-pipeline-issue-repo');
if (unhiddenTitles.length > 0) {
mod._zenHubLoadedComplete();
clearInterval(mod._zenHubLoadedWaiter);
}
},
_replaceEstimates: function () {
$('.zh-issue-estimate-badge').each(function(i, el) {
var estimate = $(el);
var dots = estimate.text().replace(/\d+/, function(match) {
return (new Array(parseInt(match) + 1)).join("|");
})
estimate.text(dots);
});
var styles = '';
styles += '.zh-issue-estimate-badge { background-color: transparent; color: #aaa; float: right; font-weight:normal }';
styles += '.zh-issue-label { padding: 0 0.3em }';
var styleBox = $('#simplifyZenhub');
if (styleBox.length > 0) {
styleBox.text(styles);
} else {
$('body').append('<style id="simplifyZenhub">' + styles + '</style>');
}
}
};
var lastCheck;
function displayIfNecessary() {
var thisCheck = mod.check();
if (thisCheck != lastCheck) {
if (thisCheck.match(mod.matches)) {
mod.attach();
} else {
mod.detach();
}
lastCheck = thisCheck;
}
}
setInterval(displayIfNecessary, 250);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment