Skip to content

Instantly share code, notes, and snippets.

@abhijit-hota
Last active July 5, 2023 11:02
Show Gist options
  • Save abhijit-hota/3cb8e2f73c3a848d27e28e6a6dacccfa to your computer and use it in GitHub Desktop.
Save abhijit-hota/3cb8e2f73c3a848d27e28e6a6dacccfa to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name NetDiff
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Show net diff in Github PRs
// @author Abhijit Hota (abhijithota.me)
// @match https://github.com/*/*/pull/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const diff = document.getElementById('diffstat');
const additions = diff.children[0].innerText.replaceAll(/[^\d]/g, '');
const deletions = diff.children[1].innerText.replaceAll(/[^\d]/g, '');
const netDiff = parseInt(additions) - parseInt(deletions);
const newSpan = document.createElement('span');
newSpan.innerText = `(Net Diff: ${netDiff > 0 ? "+" : ""}${netDiff})`;
newSpan.style.marginLeft = '0.5rem';
diff.appendChild(newSpan);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment