Skip to content

Instantly share code, notes, and snippets.

@lavoiesl
Last active June 14, 2018 20:05
Show Gist options
  • Save lavoiesl/4484f406915c7180e72f3c57f24bd40b to your computer and use it in GitHub Desktop.
Save lavoiesl/4484f406915c7180e72f3c57f24bd40b to your computer and use it in GitHub Desktop.
Remove all file diffs in a PR when path starts with vendor/
// ==UserScript==
// @name Remove Vendor
// @namespace https://gist.github.com/lavoiesl/4484f406915c7180e72f3c57f24bd40b
// @version 0.1
// @description Remove all file diffs in a PR when path starts with vendor/
// @author Julian Nadeau
// @match https://github.com/*/*/pull/*/files
// @grant none
// ==/UserScript==
(function() {
'use strict';
setTimeout(function() {
const numberWithCommas = (x) => {
var parts = x.toString().split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return parts.join(".");
}
var added = 0;
var removed = 0;
var files = 0;
console.log(document.querySelectorAll("div[data-path*='vendor/']"));
document.querySelectorAll("div[data-path*='vendor/']").forEach( function(e){
var aria = e.querySelector('.file-info > .diffstat').getAttribute('aria-label');
var matches = aria.replace(/,/g,'').match(/(\d+)/g)
if (matches != null) {
added = added + parseInt(matches[0]);
removed = removed + parseInt(matches[1]);
}
files = files + 1;
e.parentNode.style.display = "none";
})
var numFiles = parseInt(document.getElementById('files_tab_counter').innerHTML.replace(/[^\d]/g, '')) - files;
document.getElementById('files_tab_counter').innerHTML = numberWithCommas(numFiles);
var plusEl = document.querySelector('.diffstat > .text-green');
var plus = plusEl.innerHTML.replace(/[^\d]/g, '')
plusEl.innerHTML = "+" + numberWithCommas(parseInt(plus) - added);
var minusEl = document.querySelector('.diffstat > .text-red');
var minus = minusEl.innerHTML.replace(/[^\d]/g, '')
minusEl.innerHTML = "-" + numberWithCommas(parseInt(minus) - removed);
}, 2000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment