Last active
June 30, 2020 12:10
-
-
Save aal89/4e535f92ba4cdfec576941e9eb331b1a to your computer and use it in GitHub Desktop.
Show total changed lines of code for all files combined in a PR (new view) on Bitbucket. This is a TamperMonkey script.
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 Bitbucket totals in PR | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Show total changed lines of code | |
// @author You | |
// @match https://bitbucket.org/*/*/pull-requests/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
window.addEventListener('load', function() { | |
setTimeout(() => { | |
const total = (a, c) => a + c; | |
const innerToInt = ele => parseInt(ele.innerHTML); | |
const containsNumber = ele => ele.innerHTML.match(/^[+-].\d*$/); | |
const allSpanTags = Array(...document.getElementsByTagName('span')); | |
const totalForAllNumbers = allSpanTags.filter(containsNumber).map(innerToInt).reduce(total, 0); | |
const colorInt = (int) => parseInt(int) < 0 ? `<font color=darkred>${int}</font>` : `<font color=green>${int}</font>`; | |
// set the total change number next to header text for that column | |
document | |
.querySelector('#PullRequestWelcomeTourTarget-Files > section > button > span:nth-of-type(2) > span') | |
.insertAdjacentHTML('beforeend', ` <small>affected lines: <b>${colorInt(totalForAllNumbers)}</b></small>`); | |
}, 500); | |
}, false); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result:
(this particular PR removed more lines of code than it added)