Browse Source

Remove the "Projects" repo tab when there are no projects (#411)

master
Lukasz Klis 8 years ago
committed by Sindre Sorhus
parent
commit
be5631a500
  1. 5
      extension/content.css
  2. 19
      extension/content.js
  3. 5
      extension/page-detect.js
  4. 1
      readme.md
  5. 7
      test/page-detect.js

5
extension/content.css

@ -585,3 +585,8 @@ div.inline-comment-form .form-actions,
.inline-comment-form .form-actions .js-hide-inline-comment-form { .inline-comment-form .form-actions .js-hide-inline-comment-form {
float: none; float: none;
} }
/* "Add a Project" button */
#refined-github-project-new-link {
margin-top: 5px;
}

19
extension/content.js

@ -344,6 +344,20 @@ function addFilterCommentsByYou() {
} }
} }
function addProjectNewLink() {
const projectNewLink = `<a href="/${repoUrl}/projects/new" class="btn btn-sm" id="refined-github-project-new-link">Add a project</a>`;
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 // Support indent with tab key in comments
$(document).on('keydown', '.js-comment-field', event => { $(document).on('keydown', '.js-comment-field', event => {
if (event.which === 9 && !event.shiftKey) { if (event.which === 9 && !event.shiftKey) {
@ -414,6 +428,7 @@ document.addEventListener('DOMContentLoaded', () => {
if (pageDetect.isRepo()) { if (pageDetect.isRepo()) {
gitHubInjection(window, () => { gitHubInjection(window, () => {
addReleasesTab(); addReleasesTab();
removeProjectsTab();
diffFileHeader.destroy(); diffFileHeader.destroy();
enableCopyOnY.destroy(); enableCopyOnY.destroy();
markUnread.destroy(); markUnread.destroy();
@ -489,6 +504,10 @@ document.addEventListener('DOMContentLoaded', () => {
if (pageDetect.hasCode()) { if (pageDetect.hasCode()) {
linkifyURLsInCode.linkifyCode(repoUrl); linkifyURLsInCode.linkifyCode(repoUrl);
} }
if (pageDetect.isRepoSettings()) {
addProjectNewLink();
}
}); });
} }
}); });

5
extension/page-detect.js

@ -43,6 +43,8 @@ window.pageDetect = (() => {
const isNotifications = () => /\/notifications(\/participating)?/.test(location.pathname); const isNotifications = () => /\/notifications(\/participating)?/.test(location.pathname);
const isRepoSettings = () => isRepo() && /^\/settings/.test(getRepoPath());
const getOwnerAndRepo = () => { const getOwnerAndRepo = () => {
const [, ownerName, repoName] = location.pathname.split('/'); const [, ownerName, repoName] = location.pathname.split('/');
@ -81,6 +83,7 @@ window.pageDetect = (() => {
isBlame, isBlame,
isNotifications, isNotifications,
getOwnerAndRepo, getOwnerAndRepo,
isSingleFile isSingleFile,
isRepoSettings
}; };
})(); })();

1
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 annoying hover effect in the repo file browser
- Removes the comment box toolbar - Removes the comment box toolbar
- Removes tooltips - 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 - 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 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) - ~~[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)

7
test/page-detect.js

@ -156,6 +156,13 @@ test('isSingleFile', urlMatcherMacro, pageDetect.isSingleFile, [
'https://github.com/sindresorhus/refined-github/commit/57bf4' '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 => { test('getOwnerAndRepo', t => {
const ownerAndRepo = { const ownerAndRepo = {
'https://github.com/sindresorhus/refined-github/pull/148': { 'https://github.com/sindresorhus/refined-github/pull/148': {

Loading…
Cancel
Save