Skip to content

Instantly share code, notes, and snippets.

@ThHareau
Created April 21, 2020 14:19
Show Gist options
  • Save ThHareau/3f2f6623c176b92526fdf906befda644 to your computer and use it in GitHub Desktop.
Save ThHareau/3f2f6623c176b92526fdf906befda644 to your computer and use it in GitHub Desktop.
Remove ANSI escape codes from Junit summary view in MR page
// ==UserScript==
// @name Gitlab ANSI escaper
// @version 1
// @grant none
// @include /https://[^\/]*gitlab[^\/]*\/.*merge_requests\/\d+/
// @icon https://about.gitlab.com/images/press/logo/png/gitlab-icon-rgb.png
// @description Remove ANSI escape codes from Junit summary view in MR page
// ==/UserScript==
const waitForElement = (id, callback) => {
const element = document.getElementById('modal-mrwidget-reports');
if (element) {
return callback(element);
}
setTimeout(() => waitForElement(id, callback), 1000);
}
const unescapeAnsiCode = () => {
const code = document.querySelector('code.d-block');
const regex = /\[.*?m/g;
if (!code || !code.textContent.match(regex)) {
return;
}
console.debug('Replacing');
code.textContent = code.textContent.replace(regex, '')
}
const observer = new MutationObserver(unescapeAnsiCode);
waitForElement('modal-mrwidget-reports', (modal) => {
// Options for the observer (which mutations to observe)
const config = { attributes: true, childList: true, subtree: true };
observer.observe(modal, config);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment