Last active
April 26, 2021 11:50
-
-
Save billrichards/6e62799efca5d3c40d28baf0e0255e6f to your computer and use it in GitHub Desktop.
For use with the jenkins `simple theme` plugin, this js modifies the left sidebar. It hides left nav links and moves some sections to the bottom.
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
function customJenkins() { | |
var url = window.location.href.replace(window.location.protocol, ''), | |
urls = ['//127.0.0.1:8080/','//jenkins:8080/','//jenkins:8080/view/all/builds','//127.0.0.1:8080/view/all/builds']; | |
if (urls.includes(url)) { | |
// hide most of the left nav links on the pages in the urls array | |
var dontHide = ['Manage Jenkins','Build History','New Item']; | |
try { | |
var tasks = document.getElementsByClassName('task'); | |
for (var i = 0; i < tasks.length; i++) { | |
if (!dontHide.includes(tasks[i].innerText)) { | |
tasks[i].style.display = 'none'; | |
} | |
} | |
// Expand 'next executions' and 'executor status' | |
var expandThese = ['next-exec','executors']; | |
for (var j = 0; j < expandThese.length; j++) { | |
var expandThis = document.getElementById(expandThese[j]); | |
if(typeof(expandThis) !== 'undefined' && expandThis !== null) { | |
var el = expandThis.children[0].children[0].children[1]; | |
if (el.getAttribute('title') === 'expand') { | |
el.click(); | |
} else { | |
console.log(expandThese[j] + ' is not expandable'); | |
} | |
} else { | |
console.log('jenkins-custom-theme.js no element found with id ' + expandThese[j]); | |
} | |
} | |
} catch (e) { | |
console.error({'jenkins-custom-theme.js error:' : e}); | |
} | |
} else { | |
console.warn('jenkins-custom-theme.js is not configured for this url.'); | |
} | |
// Move Build Queue to the bottom of the side-panel | |
var sidePanel = document.getElementById('side-panel'), buildQueue = document.getElementById('buildQueue'); | |
if (typeof(sidePanel) !== 'undefined' && sidePanel !== null && typeof(buildQueue) !== 'undefined' && buildQueue !== null ) { | |
buildQueue.remove(); | |
buildQueue = '<div id="buildQueue" class="container-fluid pane-frame track-mouse collapsed">' + buildQueue.innerHTML + '</div>'; | |
sidePanel.insertAdjacentHTML('beforeEnd', buildQueue); | |
} | |
} | |
if (window.addEventListener) { | |
window.addEventListener('load', customJenkins, false); | |
console.info('addEventListener customJenkins()'); | |
} else if (window.attachEvent) { | |
window.attachEvent('onload', customJenkins ); | |
console.info ('attachEvent customJenkins()'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment