Skip to content

Commit

Permalink
Close #12 PR: Add Releases tab to the repo page. Fixes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
hkdobrev authored and sindresorhus committed Feb 18, 2016
1 parent 331fa4b commit cdf2b6e
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion extension/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
const path = location.pathname;
const isDashboard = path === '/';
const isRepo = /^\/[^/]+\/[^/]+/.test(path);
const username = path.split('/')[1];
const repoName = path.split('/')[2];
const isPR = () => /^\/[^/]+\/[^/]+\/pull\/\d+$/.test(location.pathname);
const isReleases = () => isRepo && /^\/[^/]+\/[^/]+\/(releases|tags)/.test(location.pathname);
const getUsername = () => $('meta[name="user-login"]').attr('content');

function linkifyBranchRefs() {
Expand All @@ -26,6 +28,30 @@ function linkifyBranchRefs() {
});
}

function addReleasesTab() {
const $repoNav = $('.js-repo-nav');
let $releasesTab = $repoNav.children('[data-selected-links~="repo_releases"]')
const hasReleases = $releasesTab.length > 0

if (!hasReleases) {
$releasesTab = $(`<a href="/${username}/${repoName}/releases" class="reponav-item" data-hotkey="g r" data-selected-links="repo_releases /${username}/${repoName}/releases" itemprop="url">
<svg aria-hidden="true" class="octicon octicon-tag" height="16" role="img" version="1.1" viewBox="0 0 14 16" width="14"><path d="M6.73 2.73c-0.47-0.47-1.11-0.73-1.77-0.73H2.5C1.13 2 0 3.13 0 4.5v2.47c0 0.66 0.27 1.3 0.73 1.77l6.06 6.06c0.39 0.39 1.02 0.39 1.41 0l4.59-4.59c0.39-0.39 0.39-1.02 0-1.41L6.73 2.73zM1.38 8.09c-0.31-0.3-0.47-0.7-0.47-1.13V4.5c0-0.88 0.72-1.59 1.59-1.59h2.47c0.42 0 0.83 0.16 1.13 0.47l6.14 6.13-4.73 4.73L1.38 8.09z m0.63-4.09h2v2H2V4z"></path></svg>
Releases
</a>`);
}

if (isReleases()) {
$repoNav.find('.selected')
.removeClass('js-selected-navigation-item selected');

$releasesTab.addClass('js-selected-navigation-item selected');
}

if (!hasReleases) {
$repoNav.append($releasesTab);
}
}

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

Expand Down Expand Up @@ -58,7 +84,8 @@ document.addEventListener('DOMContentLoaded', () => {
}

if (isRepo) {
gitHubInjection(window, () => {
gitHubInjection(window, {wait: 1}, () => {
addReleasesTab();
if (isPR()) {
linkifyBranchRefs();
}
Expand Down

0 comments on commit cdf2b6e

Please sign in to comment.