Skip to content

Instantly share code, notes, and snippets.

@beshur
Last active May 15, 2019 13:33
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 beshur/e1398ff5e741308cd29476f75d612bdd to your computer and use it in GitHub Desktop.
Save beshur/e1398ff5e741308cd29476f75d612bdd to your computer and use it in GitHub Desktop.
Compare from commit
// ==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)
})
})();
@beshur
Copy link
Author

beshur commented May 15, 2019

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.

image

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