Last active
August 29, 2015 14:23
-
-
Save DamianStanger/d1db873e9297b34160ce to your computer and use it in GitHub Desktop.
Tampermonkey script to enhance go-cd
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 Go PipeLine Filter | |
// @namespace http://pipelinefilter.foldingair.blogspot.com | |
// @version 0.1 | |
// @description Ge Server Pipelines filter | |
// @author Ingenie | |
// @match https://goserver:8154/go/ | |
// @grant none | |
// ==/UserScript== | |
(function($, debug, undefined){ | |
var init = function(){ | |
loadJQueryHotkeys(); | |
var splits = window.location.href.split("/"); | |
log(splits); | |
if(splits[4] == "home") { | |
log("filtering route 1"); | |
addFiltering(); | |
return; | |
} | |
if(splits[4] == "pipelines" && (splits[5] == undefined || splits[5] === "")) { | |
log("filtering route 2"); | |
addFiltering(); | |
return; | |
} | |
if(splits[4] == "tab" && splits[6] == "history" && splits[7] != undefined && splits[7] !== "") { | |
log("settings route 1"); | |
addSettingsButton(splits[7]); | |
return; | |
} | |
if(splits[4] == "pipelines" && (splits[5] != undefined || splits[5] !== "")) { | |
log("settings route 2"); | |
addSettingsButton(splits[5]); | |
return; | |
} | |
if(splits[4] == "admin" && splits[5] == "pipelines" && splits[6] != undefined && splits[6] !== "") { | |
log("history route"); | |
addHistoryButton(splits[6]); | |
return; | |
} | |
}; | |
var addSettingsButton = function(pipeline){ | |
$(".application_nav .tabs").append('<li id="cruise-header-tab-filter"><a href="/go/admin/pipelines/'+pipeline+'/general">SETTINGS</a></li>'); | |
} | |
var addHistoryButton = function(pipeline){ | |
$(".application_nav .tabs").append('<li id="cruise-header-tab-filter"><a href="/go/tab/pipeline/history/'+pipeline+'">HISTORY</a></li>'); | |
} | |
var addFiltering = function(){ | |
log("injecting CSS"); | |
$("head").append("<style>\ | |
#cruise-header-tab-filter .ing-fltr.ing-q{border-radius: 8px;width: 190px;margin: 5px 0px 5px 5px;}\ | |
#cruise-header-tab-filter label{padding: 2px 5px !important;position:relative;}\ | |
#cruise-header-tab-filter label span{width: 34px;height: 10px;padding: 0;position: absolute;right: 80px;top: 10px;}\ | |
#cruise-header-tab-filter label:hover{background-color: #777777 !important; border-radius: 10px; moz-border-radius: 10px; webkit-border-radius: 10px; cursor:pointer}\ | |
</style>"); | |
log("injecting UI"); | |
$(".application_nav .tabs").append('<li id="cruise-header-tab-filter"><a href="#" class="dropdown-arrow-icon" data-toggle="dropdown">FILTER</a><ul class="dropdown-menu" role="menu">\ | |
<li role="presentation"><h4 style="float:none;">By Status</h4></li>\ | |
<li role="presentation"><label for="fltr-pass"><input type="checkbox" id="fltr-pass" name="Passed" class="ing-fltr ing-status" /> Passed <span class="Passed"></span></label></li>\ | |
<li role="presentation"><label for="fltr-fail"><input type="checkbox" id="fltr-fail" name="Failed" class="ing-fltr ing-status" /> Failed <span class="Failed"></span></label></li>\ | |
<li role="presentation"><label for="fltr-building"><input type="checkbox" id="fltr-building" name="Building" class="ing-fltr ing-status" /> Building <span class="Building"></span></label></li>\ | |
<li role="presentation"><label for="fltr-unknown"><input type="checkbox" id="fltr-unknown" name="Unknown" class="ing-fltr ing-status" /> Unknown <span class="Unknown"></span></label></li>\ | |
<li role="presentation"><hr></li>\ | |
<li role="presentation"><h4 style="float:none;">By Keyword</h4></li>\ | |
<li role="presentation"><input type="text" id="fltr-q" name="q" class="ing-fltr ing-q" placeholder="Search" /></li>\ | |
<li role="presentation"><hr></li></ul></li>') | |
log("preventing menu from closing"); | |
$('#cruise-header-tab-filter label, #cruise-header-tab-filter .ing-fltr.ing-q').click(function(e) { | |
e.stopPropagation(); | |
}); | |
$('#cruise-header-tab-filter a').click(function(e) { | |
setTimeout(function(){ | |
$('#cruise-header-tab-filter .ing-fltr.ing-q').focus(); | |
}, 500) | |
}); | |
$(document).bind('keydown', 'Ctrl+f', function() { | |
$('#cruise-header-tab-filter a').click(); | |
return false; | |
}); | |
$(".pipeline").each(function(i,e){ | |
$(this).attr("data-ing-title", $(this)[0].id.toLowerCase()); | |
}); | |
setInterval(updateView, 1000); | |
$(".ing-fltr").change(function(e){ | |
updateView(); | |
}); | |
$(".ing-fltr.ing-q").on('input', function(e){ | |
updateView(); | |
}); | |
} | |
var updateView = function(){ | |
$("#pipeline_groups_container .pipeline_group").removeClass("hidden") | |
$(".pipeline").removeClass("hidden"); | |
if($(".ing-fltr:checked").length > 0 || $('#cruise-header-tab-filter .ing-fltr.ing-q').val() != "") | |
$(".pipeline").addClass("hidden"); | |
log("applying status filters"); | |
$(".ing-fltr.ing-status:checked").each(function(i,e){ | |
log( $(".pipeline").has(".stage_bar."+e.name)) | |
$(".pipeline").has(".stage_bar."+e.name).removeClass("hidden"); | |
}); | |
log("applying tag filters"); | |
$(".ing-fltr.ing-tag:checked").each(function(i,e){ | |
$(".pipeline[data-ing-title*='"+e.name.toLowerCase()+"']").removeClass("hidden"); | |
}); | |
log("applying q filter: " + $('#cruise-header-tab-filter .ing-fltr.ing-q').val()); | |
if($('#cruise-header-tab-filter .ing-fltr.ing-q').val() != "") | |
$(".pipeline[data-ing-title*='"+$('#cruise-header-tab-filter .ing-fltr.ing-q').val().toLowerCase()+"']").removeClass("hidden"); | |
fixGroupsVisibility(); | |
}; | |
var fixGroupsVisibility = function(){ | |
log("Fixing groups visibility"); | |
$("#pipeline_groups_container .pipeline_group").each(function(i, e){ | |
if($(e).find(".pipeline:visible").length < 1) { | |
$(e).addClass("hidden"); | |
} | |
}); | |
//window.scrollTo(0, 0); | |
} | |
var loadJQueryHotkeys = function(){ | |
(function(e){function t(t){if(typeof t.data==="string"){t.data={keys:t.data}}if(!t.data||!t.data.keys||typeof t.data.keys!=="string"){return}var n=t.handler,r=t.data.keys.toLowerCase().split(" ");t.handler=function(t){if(this!==t.target&&(/textarea|select/i.test(t.target.nodeName)||e.hotkeys.options.filterTextInputs&&e.inArray(t.target.type,e.hotkeys.textAcceptingInputTypes)>-1)){return}var i=t.type!=="keypress"&&e.hotkeys.specialKeys[t.which],s=String.fromCharCode(t.which).toLowerCase(),o="",u={};e.each(["alt","ctrl","shift"],function(e,n){if(t[n+"Key"]&&i!==n){o+=n+"+"}});if(t.metaKey&&!t.ctrlKey&&i!=="meta"){o+="meta+"}if(t.metaKey&&i!=="meta"&&o.indexOf("alt+ctrl+shift+")>-1){o=o.replace("alt+ctrl+shift+","hyper+")}if(i){u[o+i]=true}else{u[o+s]=true;u[o+e.hotkeys.shiftNums[s]]=true;if(o==="shift+"){u[e.hotkeys.shiftNums[s]]=true}}for(var a=0,f=r.length;a<f;a++){if(u[r[a]]){return n.apply(this,arguments)}}}}e.hotkeys={version:"0.8",specialKeys:{8:"backspace",9:"tab",10:"return",13:"return",16:"shift",17:"ctrl",18:"alt",19:"pause",20:"capslock",27:"esc",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"insert",46:"del",59:";",61:"=",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",144:"numlock",145:"scroll",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},shiftNums:{"`":"~",1:"!",2:"@",3:"#",4:"$",5:"%",6:"^",7:"&",8:"*",9:"(",0:")","-":"_","=":"+",";":": ","'":'"',",":"<",".":">","/":"?","\\":"|"},textAcceptingInputTypes:["text","password","number","email","url","range","date","month","week","time","datetime","datetime-local","search","color","tel"],options:{filterTextInputs:true}};e.each(["keydown","keyup","keypress"],function(){e.event.special[this]={add:t}})})(jQuery||this.jQuery||window.jQuery) | |
} | |
var log = function(str){ | |
if(debug) console.log(str); | |
} | |
init(); | |
}(jQuery, false)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment