Skip to content

Instantly share code, notes, and snippets.

@keyan
Created January 27, 2021 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keyan/82237d61821840a07dafc2ad002bc00a to your computer and use it in GitHub Desktop.
Save keyan/82237d61821840a07dafc2ad002bc00a to your computer and use it in GitHub Desktop.
Tapermonkey script that adds a text element to the top of a phabricator diff page with the total diff size. Doesn't have a +/- breakdown because that info isn't easy to access. This is to circumvent maintainers that refuse to add features, see https://secure.phabricator.com/T11768.
// ==UserScript==
// @name Show Total Number of Lines Modified in Diff
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Show total number of lines modified in diff at bottom of table of contents
// @author lyahdav
// @match https://phabricator.dropboxer.net/D*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var files = document.getElementsByClassName('right aphront-table-view-nodevice');
var totalLineCount = 0;
for (var i=1;i<files.length; i++) {
var file = files[i];
var lineText = file.textContent;
lineText = lineText.match(/(.+) lines/);
if (lineText == null) { continue; }
var lineCount = parseInt(lineText[1]);
totalLineCount += lineCount;
}
var countElementContent = document.createTextNode('Total number of lines modified: ' + totalLineCount);
var countElement = document.createElement('span');
countElement.appendChild(countElementContent);
countElement.style = 'font-size: 16px; color: rgb(151,234,151)';
document.getElementsByClassName('phui-header-subheader')[0].appendChild(countElement);
console.log(totalLineCount);
})();
@keyan
Copy link
Author

keyan commented Jan 27, 2021

Based off https://gist.github.com/lyahdav/30fabcfb2856a28d320114922c91a1e3, which only some small changes to work with the next element classnames as the phabricator UI has changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment