Skip to content

Instantly share code, notes, and snippets.

@jkatnik
Last active March 7, 2023 19:37
Show Gist options
  • Save jkatnik/267b617fecca55f4360cfb99053632a4 to your computer and use it in GitHub Desktop.
Save jkatnik/267b617fecca55f4360cfb99053632a4 to your computer and use it in GitHub Desktop.
BuildStatus tempermonkey script
// ==UserScript==
// @name Jenkins BuildStatus
// @namespace http://tampermonkey.net/
// @version 0.1
// @description adds BuildStatus SVG pill to Jenkins pages to ease URL building
// @author jkatnik
// @match https://*/job/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=scout24.com
// @grant none
// ==/UserScript==
function buildPill() {
const url = buildUrl();
const node = document.createElement('img');
node.src = url;
node.style.paddingLeft = '20px';
node.style.cursor = 'pointer';
node.onclick = onPillClick(url, node)
node.title = 'Click to copy HTML code';
return node;
}
function buildUrl() {
const fullProjectName = window.location.pathname.replaceAll(/\/job/g, '')
const job = fullProjectName;
return window.location.protocol + '//' + window.location.host + '/buildStatus/icon?job=' + job;
}
function onPillClick(url, node) {
return function() {
const urlTag = `<a href="${url}"><img src="${url}"></a>`;
navigator.clipboard.writeText(urlTag);
showCopiedDiv(node)
}
}
function showCopiedDiv(node) {
const text = document.createElement("span");
text.innerText = 'BuildStatus icon HTML code copied to clipboard!';
text.style.fontWeight = 'normal';
text.style.fontSize = '14px';
text.style.paddingLeft = '20px';
node.parentNode.appendChild(text);
setTimeout(() => text.remove(), 2000);
}
function install() {
if (window.jenkinsCIGlobal) {
const pill = buildPill();
document.getElementsByClassName('job-index-headline page-headline')[0].appendChild(pill);
}
}
document.onreadystatechange = install;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment