Last active
May 15, 2019 13:33
-
-
Save beshur/e1398ff5e741308cd29476f75d612bdd to your computer and use it in GitHub Desktop.
Compare from commit
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 compareFromCommit | |
// @namespace http://buznik.net/ | |
// @version 0.1.1 | |
// @description The script inserts a link to compare commits from the current commit in Github pull-request | |
// @author Alex Buznik | |
// @include /https:\/\/github.com\/(.*[^/])\/(.*[^/])\/pull\/(.*)/ | |
// @downloadURL https://gist.githubusercontent.com/beshur/e1398ff5e741308cd29476f75d612bdd/raw/compareFromCommit-TamperMonkey.js | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
let commitLinks = document.querySelectorAll('.commit-meta .commit-id') | |
let getCompareLink = (href) => { | |
return href.replace('/commits/', '/files/') + '..HEAD' | |
} | |
let createCompareEl = (href) => { | |
let el = document.createElement('a') | |
el.innerText = '⚖︎' | |
el.title = 'Compare starting from this commit' | |
el.className = 'compareFromCommit' | |
el.style = `position: absolute; | |
right: -19px; | |
margin-top: 4px; | |
font-size: 10px;` | |
el.href = href | |
return el | |
} | |
commitLinks.forEach(el => { | |
let link = getCompareLink(el.href) | |
let container = el.parentNode.parentNode | |
container.insertBefore(createCompareEl(link), el.parentNode) | |
}) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The script creates the link to compare commit in the Github pull-request starting from the current commit.
Useful when you have updated the pull-request and want to direct reviewers to that portion of code that's changed.
Inserts the scale icon next to the commit hash.
Please remember you need to click the commit, that is previous to the start of the range.