Last active
July 5, 2023 11:02
-
-
Save abhijit-hota/3cb8e2f73c3a848d27e28e6a6dacccfa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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