diff options
author | 2020-04-12 18:51:25 -0400 | |
---|---|---|
committer | 2020-04-13 00:51:25 +0200 | |
commit | ed2dc7b08b52efe00dcca41248ce35ef7f5ef04f (patch) | |
tree | 97a017fd6cbe6c381d90507cc9ab4460c9695205 | |
parent | 15600fe3303abee0724665356de9e0cedf06517e (diff) | |
download | refined-github-ed2dc7b08b52efe00dcca41248ce35ef7f5ef04f.tar.gz refined-github-ed2dc7b08b52efe00dcca41248ce35ef7f5ef04f.tar.zst refined-github-ed2dc7b08b52efe00dcca41248ce35ef7f5ef04f.zip |
Add `discussion-links-on-repo-lists` feature (#2981)
Co-Authored-By: Federico Brigante <opensource@bfred.it>
-rw-r--r-- | readme.md | 1 | ||||
-rw-r--r-- | source/features/discussion-links-on-repo-lists.tsx | 60 | ||||
-rw-r--r-- | source/libs/page-detect.ts | 8 | ||||
-rw-r--r-- | source/refined-github.ts | 3 |
4 files changed, 70 insertions, 2 deletions
@@ -282,6 +282,7 @@ Thanks for contributing! π¦π - [](# "linkify-user-location") [Linkifies the user location in their hovercard and profile page.](https://user-images.githubusercontent.com/1402241/69076885-00d3a100-0a67-11ea-952a-690acec0826f.png) - [](# "user-local-time") [Shows the user local time in their hovercard (based on their last commit).](https://user-images.githubusercontent.com/1402241/69863648-ef449180-12cf-11ea-8f36-7c92fc487f31.gif) - [](# "hide-zero-packages") [Hides the `Packages` tab on user profiles if itβs empty.](https://user-images.githubusercontent.com/35382021/62426530-688ef780-b6d5-11e9-93f2-515110aed1eb.jpg) +- [](# "discussion-links-on-repo-lists") [Adds a link to the issues and pulls on the user profile repository tab and global search.](https://user-images.githubusercontent.com/16872793/78712349-82c54900-78e6-11ea-8328-3c2d39a78862.png) <!-- Refer to style guide above. Keep this message between sections. --> diff --git a/source/features/discussion-links-on-repo-lists.tsx b/source/features/discussion-links-on-repo-lists.tsx new file mode 100644 index 00000000..ce964a45 --- /dev/null +++ b/source/features/discussion-links-on-repo-lists.tsx @@ -0,0 +1,60 @@ +import React from 'dom-chef'; +import select from 'select-dom'; +import issueIcon from 'octicon/issue-opened.svg'; +import pullRequestIcon from 'octicon/git-pull-request.svg'; +import features from '../libs/features'; +import observeElement from '../libs/simplified-element-observer'; + +function init(): void { + const repositories = select.all<HTMLAnchorElement>([ + '[itemprop="name codeRepository"]:not(.rgh-discussion-links)', // `isUserProfileRepoTab` + '[data-hydro-click*=\'"model_name":"Repository"\']' // `isGlobalSearchResults` + ]); + + for (const repositoryLink of repositories) { + repositoryLink.classList.add('rgh-discussion-links'); + + const repository = repositoryLink.closest('li')!; + + // Remove the "X issues need help" link + select('[href*="issues?q=label%3A%22help+wanted"]', repository)?.remove(); + + // Place before the "Updated on" element + select('relative-time', repository)!.previousSibling!.before( + <a + className="muted-link mr-3" + href={repositoryLink.href + '/issues?q=is%3Aissue+is%3Aopen'} + > + {issueIcon()} + </a>, + <a + className="muted-link mr-3" + href={repositoryLink.href + '/pulls?q=is%3Apr+is%3Aopen'} + > + {pullRequestIcon()} + </a> + ); + } +} + +features.add({ + id: __featureName__, + description: 'Adds a link to the issues and pulls on the user profile repository tab and global search.', + screenshot: 'https://user-images.githubusercontent.com/16872793/78712349-82c54900-78e6-11ea-8328-3c2d39a78862.png' +}, { + include: [ + features.isUserProfileRepoTab, + features.isGlobalSearchResults + ], + load: features.onAjaxedPages, + init +}, { + include: [ + features.isUserProfileRepoTab + ], + load: features.onAjaxedPages, + init: () => { + observeElement('#user-repositories-list', init); + return false; + } +}); diff --git a/source/libs/page-detect.ts b/source/libs/page-detect.ts index 8dbe9a73..2c48d300 100644 --- a/source/libs/page-detect.ts +++ b/source/libs/page-detect.ts @@ -67,7 +67,8 @@ export const _isDashboard = [ 'https://github.com/orgs/edit/dashboard', 'https://github.big-corp.com/', 'https://not-github.com/', - 'https://my-little-hub.com/' + 'https://my-little-hub.com/', + 'https://github.com/?tab=repositories' // Gotcha for `isUserProfileRepoTab` ]; export const isEnterprise = (): boolean => location.hostname !== 'github.com' && location.hostname !== 'gist.github.com'; @@ -373,6 +374,11 @@ export const _isBranches = [ export const isUserProfile = (): boolean => select.exists('.user-profile-nav'); export const _isUserProfile = domBased; +export const isUserProfileRepoTab = (): boolean => + isUserProfile() && + new URLSearchParams(location.search).get('tab') === 'repositories'; +export const _isUserProfileRepoTab = domBased; + export const isSingleTagPage = (): boolean => /^(releases\/tag)/.test(getRepoPath()!); export const _isSingleTagPage = [ 'https://github.com/sindresorhus/refined-github/releases/tag/v1.0.0-beta.4', diff --git a/source/refined-github.ts b/source/refined-github.ts index 817d35ce..d70b1882 100644 --- a/source/refined-github.ts +++ b/source/refined-github.ts @@ -60,9 +60,10 @@ import './features/linkify-branch-references'; import './features/batch-open-issues'; import './features/hide-useless-comments'; import './features/navigate-pages-with-arrow-keys'; +import './features/discussion-links-on-repo-lists'; import './features/global-discussion-list-filters'; import './features/filter-comments-by-you'; -import './features/sort-issues-by-update-time'; // Must be after global-discussion-list-filters and filter-comments-by-you +import './features/sort-issues-by-update-time'; // Must be after global-discussion-list-filters and filter-comments-by-you and discussion-links-on-repo-lists import './features/pinned-issues-update-time'; import './features/latest-tag-button'; import './features/default-branch-button'; |