Skip to content

Instantly share code, notes, and snippets.

@marcelovani
Last active July 26, 2017 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcelovani/55eafcc21e852b68f5c8 to your computer and use it in GitHub Desktop.
Save marcelovani/55eafcc21e852b68f5c8 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Jenkins Tweaks
// @namespace work
// @description Tweaks for UI
// @include *jenkins.dennis.co.uk*
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
function uiTweaksConsole() {
// Change color of console output
jQuery("#out").css("background-color", "#000").css("color", "#0E0");
jQuery("#out a").css("color", "#4d96ff");
jQuery("#out a:visited").css("color", "#ececec");
}
// Pre-populate rebuild form.
function uiTweaksRebuild() {
// Append rebuild button to Build history.
jQuery("#buildHistory .build-row .middle-align").append('<span style="cursor: pointer;" class="monkeyRebuild">Rebuild</span>');
// Callback for rebuild link.
jQuery(".monkeyRebuild").click(function() {
$build_link = jQuery("a:contains('Build with Parameters')").attr('href');
if (typeof $build_link !== 'undefined' && (GM_getValue("gmrbuildlink") === 'undefined' || GM_getValue("gmrbuildlink") === '')) {
$build_link = $build_link.replace('?delay=0sec', '');
// Record step.
GM_setValue("gmrstep", "1");
GM_setValue("gmrbuildlink", $build_link);
}
// Get the url of previous build and change to parameters tab.
$href = jQuery(this).parent().parent().find('.model-link').attr('href');
$href = $href + 'parameters/';
GM_setValue("gmrhref", $href);
GM_setValue("gmrstep", "2");
// Open parameters tab
window.location.href = $href;
return;
});
// Append the copy button to the form.
if (GM_getValue("gmrstep") == '2') {
var storage = {};
// Store form data in a cookie.
jQuery.each(jQuery("#main-panel table.pane tr"), function(key, row) {
// Grab the field names.
var setting_name = jQuery("#main-panel table.pane tr:nth-child(" + key + ") .setting-name").html();
if (typeof setting_name != 'undefined') {
storage[setting_name] = '';
}
// Grab field values.
$selector = "#main-panel table.pane tr:nth-child(" + key + ") .setting-main";
if (typeof jQuery($selector) != 'undefined') {
var myArray = ["aa", "bb"];
$input_types = ['textarea', 'input'];
for (var n in $input_types) {
if (typeof $input_types[n] == 'string') {
$input_value = jQuery($selector + " " + $input_types[n]).val();
if (typeof $input_value != 'undefined') {
storage[setting_name] = $input_value;
}
}
}
}
});
// Store params in cookie.
GM_setValue("gmrparams", JSON.stringify(storage));
GM_setValue("gmrstep", "3");
// Go to build page.
window.location.href = GM_getValue("gmrbuildlink");
return;
}
if (GM_getValue("gmrstep") == '3') {
$params = JSON.parse(GM_getValue("gmrparams"));
// Remove expire date.
delete $params.ExpiryDate;
console.log($params);
jQuery.each($params, function(key, value) {
//console.log( key );
//console.log(value);
// Fill in the form.
jQuery("#main-panel tr div input[value='" + key + "']").next().val(value);
// Reset storage.
GM_setValue("gmrstep");
GM_setValue("gmrbuildlink");
GM_setValue("gmrparams");
});
}
console.log(GM_getValue("gmrstep"));
console.log(GM_getValue("gmrbuildlink"));
console.log(GM_getValue("gmrparams"));
}
function getUrlVars() {
var vars = [],
hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
jQuery(document).ready(function() {
uiTweaksRebuild();
uiTweaksConsole();
setInterval(uiTweaksConsole, 15000);
});
@marcelovani
Copy link
Author

Added Rebuild (Automatically re-fill the form)

@marcelovani
Copy link
Author

Fixed bug with storage keeping previous path

@marcelovani
Copy link
Author

Add rebuild button to all previous builds

@marcelovani
Copy link
Author

Allow GM_getValue and GM_setValue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment