From cdf2b6ea0678cd59df85f75df499e58eb3383fad Mon Sep 17 00:00:00 2001 From: Haralan Dobrev Date: Thu, 18 Feb 2016 14:46:43 +0700 Subject: [PATCH] Close #12 PR: Add `Releases` tab to the repo page. Fixes #8 --- extension/content.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/extension/content.js b/extension/content.js index d54aa83f6c6..61281e490b2 100755 --- a/extension/content.js +++ b/extension/content.js @@ -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() { @@ -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 = $(``); + } + + 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(); @@ -58,7 +84,8 @@ document.addEventListener('DOMContentLoaded', () => { } if (isRepo) { - gitHubInjection(window, () => { + gitHubInjection(window, {wait: 1}, () => { + addReleasesTab(); if (isPR()) { linkifyBranchRefs(); }