diff --git a/extension/content.css b/extension/content.css index 0a080be..f101c30 100644 --- a/extension/content.css +++ b/extension/content.css @@ -585,3 +585,8 @@ div.inline-comment-form .form-actions, .inline-comment-form .form-actions .js-hide-inline-comment-form { float: none; } + +/* "Add a Project" button */ +#refined-github-project-new-link { + margin-top: 5px; +} diff --git a/extension/content.js b/extension/content.js index 291f411..d5901ca 100644 --- a/extension/content.js +++ b/extension/content.js @@ -344,6 +344,20 @@ function addFilterCommentsByYou() { } } +function addProjectNewLink() { + const projectNewLink = `Add a project`; + if ($('#projects-feature:checked').length > 0 && $('#refined-github-project-new-link').length === 0) { + $(`#projects-feature ~ p.note`).after(projectNewLink); + } +} + +function removeProjectsTab() { + const projectsTab = $('.js-repo-nav').find('.reponav-item[data-selected-links^="repo_projects"]'); + if (projectsTab.length > 0 && projectsTab.find('.Counter').text() === '0') { + projectsTab.remove(); + } +} + // Support indent with tab key in comments $(document).on('keydown', '.js-comment-field', event => { if (event.which === 9 && !event.shiftKey) { @@ -414,6 +428,7 @@ document.addEventListener('DOMContentLoaded', () => { if (pageDetect.isRepo()) { gitHubInjection(window, () => { addReleasesTab(); + removeProjectsTab(); diffFileHeader.destroy(); enableCopyOnY.destroy(); markUnread.destroy(); @@ -489,6 +504,10 @@ document.addEventListener('DOMContentLoaded', () => { if (pageDetect.hasCode()) { linkifyURLsInCode.linkifyCode(repoUrl); } + + if (pageDetect.isRepoSettings()) { + addProjectNewLink(); + } }); } }); diff --git a/extension/page-detect.js b/extension/page-detect.js index 8924ef6..e327d17 100644 --- a/extension/page-detect.js +++ b/extension/page-detect.js @@ -43,6 +43,8 @@ window.pageDetect = (() => { const isNotifications = () => /\/notifications(\/participating)?/.test(location.pathname); + const isRepoSettings = () => isRepo() && /^\/settings/.test(getRepoPath()); + const getOwnerAndRepo = () => { const [, ownerName, repoName] = location.pathname.split('/'); @@ -81,6 +83,7 @@ window.pageDetect = (() => { isBlame, isNotifications, getOwnerAndRepo, - isSingleFile + isSingleFile, + isRepoSettings }; })(); diff --git a/readme.md b/readme.md index a630101..94c9d3a 100644 --- a/readme.md +++ b/readme.md @@ -43,6 +43,7 @@ Our hope is that GitHub will notice and implement some of these much needed impr - Removes annoying hover effect in the repo file browser - Removes the comment box toolbar - Removes tooltips +- Removes the "Projects" repo tab when there are no projects - Copy canonical link to file when [the `y` hotkey](https://help.github.com/articles/getting-permanent-links-to-files/) is used - ~~[Adds blame links for parent commits in blame view](https://github.com/sindresorhus/refined-github/issues/2#issuecomment-189141373)~~ [Implemented by GitHub](https://github.com/blog/2304-navigate-file-history-faster-with-improved-blame-view) - ~~[Adds ability to collapse/expand files in a pull request diff](https://cloud.githubusercontent.com/assets/170270/13954167/40caa604-f072-11e5-89ba-3145217c4e28.png)~~ [Implemented by GitHub](https://cloud.githubusercontent.com/assets/170270/25772137/6a6b678e-3296-11e7-97c7-02e31ef17743.png) diff --git a/test/page-detect.js b/test/page-detect.js index 8857470..b84a3e0 100644 --- a/test/page-detect.js +++ b/test/page-detect.js @@ -156,6 +156,13 @@ test('isSingleFile', urlMatcherMacro, pageDetect.isSingleFile, [ 'https://github.com/sindresorhus/refined-github/commit/57bf4' ]); +test('isRepoSettings', urlMatcherMacro, pageDetect.isRepoSettings, [ + 'https://github.com/sindresorhus/refined-github/settings', + 'https://github.com/sindresorhus/refined-github/settings/branches' +], [ + 'https://github.com/sindresorhus/refined-github/releases' +]); + test('getOwnerAndRepo', t => { const ownerAndRepo = { 'https://github.com/sindresorhus/refined-github/pull/148': {