summaryrefslogtreecommitdiff
path: root/source/features/conversation-links-on-repo-lists.tsx
blob: 7f91d3fde90b597779fcdcc946c1209563482f71 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import React from 'dom-chef';
import select from 'select-dom';
import onetime from 'onetime';
import {observe} from 'selector-observer';
import IssueIcon from 'octicon/issue-opened.svg';
import * as pageDetect from 'github-url-detection';
import PullRequestIcon from 'octicon/git-pull-request.svg';

import features from '.';

function init(): void {
	observe([
		'[itemprop="name codeRepository"]:not(.rgh-discussion-links)', // `isUserProfileRepoTab`
		'[data-hydro-click*=\'"model_name":"Repository"\']:not(.rgh-discussion-links)' // `isGlobalSearchResults`
	].join(), {
		constructor: HTMLAnchorElement,
		add(repositoryLink) {
			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>
			);
		}
	});
}

void features.add(__filebasename, {
	include: [
		pageDetect.isUserProfileRepoTab,
		pageDetect.isGlobalSearchResults
	],
	init: onetime(init)
});