Bitbucket Total Changed Lines

Show total number of added/removed lines

  1. // ==UserScript==
  2. // @name Bitbucket Total Changed Lines
  3. // @namespace https://bitbucket.org/
  4. // @description Show total number of added/removed lines
  5. // @match https://bitbucket.org/*
  6. // @version 0.1
  7. // ==/UserScript==
  8.  
  9. // a function that loads jQuery and calls a callback function when jQuery has finished loading
  10. function addJQuery(callback) {
  11. var script = document.createElement('script');
  12. script.setAttribute('src', '//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js');
  13. script.addEventListener('load', function() {
  14. var script = document.createElement('script');
  15. script.textContent = 'window.jQ=jQuery.noConflict(true);(' + callback.toString() + ')();';
  16. document.body.appendChild(script);
  17. }, false);
  18. document.body.appendChild(script);
  19. }
  20.  
  21. // the guts of this userscript
  22. function main() {
  23. // jQ replaces $ to avoid conflicts.
  24. setTimeout(function() {
  25. var linesAdded = jQ('.lines-added');
  26. var linesRemoved = jQ('.lines-removed');
  27.  
  28. var totalAdded = 0;
  29. for (var i = 0; i < linesAdded.length; i++) {
  30. totalAdded += parseInt(jQ(linesAdded[i]).text(), 10);
  31. }
  32.  
  33. var totalRemoved = 0;
  34. for (var j = 0; j < linesRemoved.length; j++) {
  35. totalRemoved += parseInt(jQ(linesRemoved[j]).text(), 10);
  36. }
  37.  
  38. $('.iterable-item.file:last').after(
  39. '<li><div class="commit-file-diff-stats">' +
  40. '<span class="lines-added">+' + totalAdded + '</span>' +
  41. '<span class="lines-removed">' + totalRemoved + '</span>' +
  42. '</div></li>'
  43. );
  44. }, 3000);
  45. }
  46.  
  47. // load jQuery and execute the main function
  48. addJQuery(main);