Skip to content

Instantly share code, notes, and snippets.

@hidechae
Last active August 29, 2015 14:07
Show Gist options
  • Save hidechae/54b41257fcee722af40b to your computer and use it in GitHub Desktop.
Save hidechae/54b41257fcee722af40b to your computer and use it in GitHub Desktop.
Userscript for tampermonkey. This is thema for jenkins console.
// ==UserScript==
// @name jenkins console style
// @namespace http://use.i.E.your.homepage/
// @version 0.1
// @description change jenkins console style like travis ci
// @match http://jenkins.../*/console*
// @copyright 2013+
// ==/UserScript==
var lineColor = 'white';
var lineNumberColor = '#999';
var backgroundColor = '#222';
var hiliteColor = '#444';
var url = document.URL;
if (url.match(/.*consoleText$/)) {
var body = document.getElementsByTagName('body')[0];
body.style.margin = '0px';
}
var executed = false;
function process() {
var preTagList = document.getElementsByTagName('pre');
for (var i = 0; i < preTagList.length; i++) {
var preTag = preTagList[i];
if (preTag.id == 'out') {
continue;
}
executed = true;
preTag.style.background = backgroundColor;
preTag.style.color = lineColor;
var textPerLine = preTag.innerHTML.split('\n');
var consoleLog = '<table style="padding-top: 10px; padding-bottom: 10px; width: 100%">';
for (var j = 0; j < textPerLine.length; j++) {
var line = textPerLine[j];
var lineNumber = j + 1;
var id = 'L' + lineNumber;
consoleLog +=
'<tr id="' + id + '">' +
'<td style="padding-left: 10px;">' +
'<a href="#' + id + '" style="color: ' + lineNumberColor + '; text-decoration: none;">' + lineNumber + '</a>' +
'</td>' +
'<td style="color: ' + lineColor + '; padding-left: 10px;">' + line + '</td>' +
'</tr>';
// get result
if (typeof(result) == 'undefined' && line.match(/Tests: \d+(, Assertions: \d+)?(, Failures: \d+)?(, Errors: \d+)?(, Incomplete: \d+)?(, Skipped: \d+)?./)) {
var result = 'result: ' + line;
}
if (line.match(/There.*error(s)?:/)) {
var errorLineId = id;
}
if (line.match(/There.*failure(s)?:/)) {
var failureLineId = id;
}
}
consoleLog += '</table>';
if (typeof(result) != 'undefined') {
if (typeof(errorLineId) != 'undefined') {
result = result.replace('Errors', '<a href="#' + errorLineId + '" style="color: ' + lineColor + ';">Errors</a>');
}
if (typeof(failureLineId) != 'undefined') {
result = result.replace('Failures', '<a href="#' + failureLineId + '" style="color: ' + lineColor + ';">Failures</a>');
}
var resultContent = '<div style="padding: 10px;">' + result + '</div>';
} else {
var resultContent = '';
}
preTag.innerHTML = resultContent + consoleLog;
}
}
process();
setInterval(function() {
if (executed == true) {
clearInterval(process);
return;
}
process();
}, 10);
document.addEventListener('mouseover', function(e) {
var parent = e.target.parentElement || e.target.parentNode;
var id = parent.id;
if (typeof(id) != 'undefined' && id.match(/L\d+/)) {
var elem = document.getElementById(id);
elem.style.background = hiliteColor;
}
});
document.addEventListener('mouseout', function(e) {
var parent = e.target.parentElement || e.target.parentNode;
var id = parent.id;
if (typeof(id) != 'undefined' && id.match(/L\d+/)) {
var elem = document.getElementById(id);
elem.style.background = backgroundColor;
}
});
@hidechae
Copy link
Author

hidechae commented Oct 8, 2014

Please edit match url before use.

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