Last active
September 27, 2017 09:14
-
-
Save epochcoder/7419e3ba083e5a1daf8ab19e001cba7a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 GoCD pipeline closer | |
// @namespace http://tampermonkey.net/ | |
// @version 0.3 | |
// @description Add close buttons to pipelines | |
// @author Willie Scholtz | |
// @match http://*/go/* | |
// @grant none | |
// ==/UserScript== | |
(function($) { | |
var close = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACRElEQVQ4T4VTz2sTQRR+b3YTTGIsehAP1aMX/wLxYJMteqpocXYrkroJbaWiFwUL4lm8KFoKatDNqghmJ8SbiCXZSAVP3ryINw8qVWnRxrZJdp5M7IY1at3bvHnfj/f2G4S+b2RkKrmS7BxnQAckkKauGWBAkl6uQrPySojVKASjB8Oyx4jwGBKVlrfHa6+Lxba655zHv2BqGIHZBFDxPccLcT2CrJm/TADffK802+/qNxFunweELTXPvaLqXQKlLAl3/g8cEhlm4QKhfF8vuwLVzM1Eu1T3SpZqyJw4tU8nbWn+sfMhqjzMx/d0WGxbo3zvjRI2uC1+QDOHGaswzqRcrAn3mQIMcXuXBni7FcSmF6rFj6p2aCy/uyNhTm93Jp8/ebjYFeKFI4xBGg0rf2d5IHY2XFhIwoDdkiCnIdB1TQvmWgCTC6L0OXS1n/NEAtM3MWPZd/2yO9G/OOVEkah6G2gqCg57M2be/TfB6MQg6MEsI0TlpCHcT/0iXQI1wg65ck4I0QobhjbAAcFpDUhTTtqBfibciepTIyTZ1huY5XaOEL76nvu0O38EHNr+22IN0z4qCZK4sYz7dc8xf2VifG9Lakv9MysSBDbgC+et+o1Znq/IFJ3sBiljFkxGcrAm3OubpTC8y5r2DCG888tutRdlw7QvAbD1mudc24QEs6Z9EYhhXThXe1HuMVs2RwmWBPZgDb7Phy+vuzBMHSbCHDF6pJT/eEzRgCRZepQIDhJQXNUZwrqU9IJSUG247lrU4U8vOw0T+eD34QAAAABJRU5ErkJggg==', | |
pipelines = 'div.pipelines div.pipeline', | |
pipeline_header = 'div.pipeline_header', | |
pipeline_header_name = 'div.pipeline_name_link > h3 > a' | |
; | |
function addGlobalStyle(css) { | |
var head, style; | |
head = document.getElementsByTagName('head')[0]; | |
if (!head) { | |
return; | |
} | |
style = document.createElement('style'); | |
style.type = 'text/css'; | |
style.innerHTML = css; | |
head.appendChild(style); | |
} | |
function addClose() { | |
console.log('adding close button to pipelines...'); | |
$(pipelines).each(function(i, el) { | |
var actions = $(el).find(pipeline_header + ' > div.pipeline_actions'), a; | |
a = $('<a href="javascript:void(0);" class="icon16 close">'); | |
a.appendTo(actions).css({ | |
backgroundImage: 'url(' + close + ')', | |
padding: '1px 4px 0 0', | |
float: 'right' | |
}); | |
}); | |
} | |
$(document).on('dashboard-refresh-completed', function(element, isPartialRefresh) { | |
if (!isPartialRefresh) { | |
addClose(); | |
} | |
}); | |
$(document).on('click', 'div.pipeline_actions > a.close', function() { | |
var pipeline_name = $(this).parents(pipeline_header).find(pipeline_header_name).text(); | |
console.log('closing pipeline: ' + pipeline_name + '...'); | |
$('div#pipelines_selector').find('div.selector_pipeline > label').filter(function(i, e) { | |
return $(e).text() === pipeline_name; | |
}).siblings('input[type="checkbox"]').prop('checked', false); | |
$('#apply_pipelines_selector').click(); | |
}); | |
addClose(); | |
// make row bigger for gocd version 16.12.0 | |
addGlobalStyle('div.row { max-width: 99999px !important; margin: 0 50px !important }'); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment