Last active
December 21, 2024 18:39
-
-
Save pjpscriv/f55fac62eb4a6a22e048ab80e0d55666 to your computer and use it in GitHub Desktop.
Userscript to add regex capability to the Istanbul HTML report search function. Specifically targeting reports generated from GitLab pipelines, but can be modified to run anywhere.
This file contains hidden or 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
// ==UserScript== | |
// @name Instanbul HTML Report RegEx Search | |
// @namespace https://pjpscriv.com/ | |
// @version 2024-08-25 | |
// @description Add regex capability to the Istanbul HTML report search function | |
// @author pjpscriv | |
// @match https://*.gitlab.io/-/*/-/jobs/*/artifacts/*/coverage/*/index.html | |
// @icon https://avatars.githubusercontent.com/u/13523395?s=48&v=4 | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
window.addEventListener('load', function() { | |
// Override onFilterInput | |
window.onFilterInput = function() { | |
const searchValue = document.getElementById('fileSearch').value; | |
const rows = document.getElementsByTagName('tbody')[0].children; | |
// RegEx filtering logic ✨ | |
let searchRegex; | |
try { | |
searchRegex = new RegExp(searchValue, 'i'); | |
} catch (error) { | |
searchRegex = null; | |
} | |
for (let i = 0; i < rows.length; i++) { | |
const row = rows[i]; | |
let isMatch = false; | |
if (searchRegex) { | |
isMatch = searchRegex.test(row.textContent); | |
} else { | |
isMatch = row.textContent.toLowerCase().includes(searchValue.toLowerCase()); | |
} | |
row.style.display = isMatch ? '' : 'none'; | |
} | |
}; | |
// Update the event listener with the new onFilterInput | |
document.getElementById('fileSearch').oninput = window.onFilterInput; | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment