Skip to content

Commit

Permalink
Close #24 PR: Add blame parent links next to each commit. Fixes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
hkdobrev authored and sindresorhus committed Feb 26, 2016
1 parent 16bb8bc commit a4b3061
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions extension/content.js
Expand Up @@ -8,6 +8,7 @@ const repoName = path.split('/')[2];
const isPR = () => /^\/[^/]+\/[^/]+\/pull\/\d+$/.test(location.pathname);
const isIssue = () => /^\/[^/]+\/[^/]+\/issues\/\d+$/.test(location.pathname);
const isReleases = () => isRepo && /^\/[^/]+\/[^/]+\/(releases|tags)/.test(location.pathname);
const isBlame = () => isRepo && /^\/[^/]+\/[^/]+\/blame\//.test(location.pathname);
const getUsername = () => $('meta[name="user-login"]').attr('content');
const uselessContent = {
upvote: {text: ['+1\n'], emoji: [':+1:']},
Expand Down Expand Up @@ -133,6 +134,23 @@ function infinitelyMore() {
}
}

function addBlameParentLinks() {
$('.blame-sha').each((index, commitLink) => {
const $commitLink = $(commitLink);
const $blameParentLink = $commitLink.clone();
const commitSha = /\w{40}$/.exec(commitLink.href)[0];

$blameParentLink
.text('Blame ^')
.prop('href', location.pathname.replace(
/(\/blame\/)[^\/]+/,
'$1' + commitSha + encodeURI('^')
));

$commitLink.nextAll('.blame-commit-meta').append($blameParentLink);
});
}

document.addEventListener('DOMContentLoaded', () => {
const username = getUsername();

Expand Down Expand Up @@ -166,6 +184,9 @@ document.addEventListener('DOMContentLoaded', () => {
if (isPR() || isIssue()) {
moveVotes();
}
if (isBlame()) {
addBlameParentLinks();
}
});
}
});
1 change: 1 addition & 0 deletions readme.md
Expand Up @@ -18,6 +18,7 @@ My hope is that GitHub will notice and implement some of these much needed impro
- Removes annoying hover effect in the repo file browser
- Removes the comment box toolbar
- Moves the dashboard organization switcher to the right column
- Adds blame links for parent commits in blame view

And [lots](extension/content.css) [more...](extension/content.js)

Expand Down

0 comments on commit a4b3061

Please sign in to comment.