Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Show total changed lines of code for all files combined in a PR (new view) on Bitbucket. This is a TamperMonkey script.
// ==UserScript==
// @name Bitbucket totals in PR
// @namespace
// @version 0.1
// @description Show total changed lines of code
// @author You
// @match*/*/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
.querySelector('#PullRequestWelcomeTourTarget-Files > section > button > span:nth-of-type(2) > span')
.insertAdjacentHTML('beforeend', ` <small>affected lines: <b>${colorInt(totalForAllNumbers)}</b></small>`);
}, 500);
}, false);

This comment has been minimized.

Copy link
Owner Author

@aal89 aal89 commented Jun 30, 2020



(this particular PR removed more lines of code than it added)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.