summaryrefslogtreecommitdiff
path: root/source/features/show-user-top-repositories.tsx
blob: 7885fe07da96268fba0e643458b691cac18dd2da (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
import React from 'dom-chef';
import * as pageDetect from 'github-url-detection';

import features from '../feature-manager.js';
import observe from '../helpers/selector-observer.js';

function addLink(showCaseTitle: Element): void {
	const url = new URL(location.pathname, location.href);
	// DO NOT add type: 'source' since forks could also have many stars
	url.search = new URLSearchParams({
		tab: 'repositories',
		sort: 'stargazers',
	}).toString();

	showCaseTitle.firstChild!.after(' / ', <a href={url.href}>Top repositories</a>);
}

function init(signal: AbortSignal): void {
	observe('.js-pinned-items-reorder-container h2', addLink, {signal});
}

void features.add(import.meta.url, {
	include: [
		pageDetect.isUserProfileMainTab,
	],
	init,
});