Skip to content

Instantly share code, notes, and snippets.

@a-r-m-i-n
Created October 16, 2016 15:09
Show Gist options
  • Save a-r-m-i-n/d050244346ab5e5078d2fb1c2c2e5a0b to your computer and use it in GitHub Desktop.
Save a-r-m-i-n/d050244346ab5e5078d2fb1c2c2e5a0b to your computer and use it in GitHub Desktop.
Calculate difference between added and removed lines and displays it in Bitbucket commits
// ==UserScript==
// @name Bitbucket Commit Line Difference
// @namespace ArminVieweg
// @version 0.1
// @description Calculate difference between added and removed lines and displays it in Bitbucket commits
// @author Armin Vieweg <[email protected]>
// @match https://bitbucket.org/*/*/commits/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var totalDifference = 0;
var $lastLine = null;
// Your code here...
$('.lines-added').each(function(){
$lastLine = $(this);
var added = parseInt($(this).text());
var removed = parseInt($(this).next('.lines-removed').text());
var difference = added + removed;
totalDifference = totalDifference + difference;
$(this).clone().text(difference).css('background', '#ccc').css('color', difference < 0 ? 'red' : 'black').css('marginLeft', '6px').insertAfter($(this).next('.lines-removed'));
});
$lastLine.closest('.iterable-item').clone().html('<b style="display:inline-block;padding-top:5px; color:' + (totalDifference < 0 ? 'red' : 'black') + ';">' + totalDifference + ' lines</b>').insertAfter($lastLine.closest('.iterable-item'));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment