Skip to content

Instantly share code, notes, and snippets.

@fabien-d
Last active May 14, 2018 17:58
Show Gist options
  • Save fabien-d/7edc8353af3176bd35ef72d640e2e467 to your computer and use it in GitHub Desktop.
Save fabien-d/7edc8353af3176bd35ef72d640e2e467 to your computer and use it in GitHub Desktop.
Filter GitHub pull request changed files by extension
/**
* Prompt and filter a PR's changed files by the given extension(s).
*/
var els=document.getElementsByClassName('user-select-contain');
var input = prompt('File extension(s), comma separated');
els = [].forEach.call(els, function(el) {
var parent = el;
while (parent && !parent.classList.contains('js-details-container')) {
parent = parent.parentNode;
}
var exts = input.split(',');
var matches = exts.filter(function(ext) {
return el.textContent.trim().endsWith(ext.trim());
});
parent.style.display = matches.length ? 'block' : 'none';
});
// bookmarklet (includes String.prototype.endsWith polyfill)
javascript:(function(){String.prototype.endsWith||(String.prototype.endsWith=function(t,e){var n=this.toString();("number"!=typeof e||!isFinite(e)||Math.floor(e)!==e||e>n.length)&&(e=n.length),e-=t.length;var i=n.indexOf(t,e);return-1!==i&&i===e});var els=document.getElementsByClassName("user-select-contain"),input=prompt("File extension(s), comma separated");els=[].forEach.call(els,function(t){for(var e=t;e&&!e.classList.contains("js-details-container");)e=e.parentNode;var n=input.split(","),i=n.filter(function(e){return t.textContent.trim().endsWith(e.trim())});e.style.display=i.length?"block":"none"});}())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment