summaryrefslogtreecommitdiff
path: root/source/features/show-user-top-repositories.tsx
blob: 96f5da1ac10196e4992202bd47cdd421d8c69471 (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
import React from 'dom-chef';
import select from 'select-dom';
import features from '../libs/features';
import {getCleanPathname} from '../libs/utils';

function buildUrl(queryField: string): URL {
	const url = new URL('/search', location.href);
	url.searchParams.set('o', 'desc');
	url.searchParams.set('q', `user:${getCleanPathname()}`);
	url.searchParams.set('s', queryField);
	url.searchParams.set('type', 'Repositories');
	return url;
}

function init(): false | void {
	const showcaseTitle = select('.js-pinned-items-reorder-container .text-normal')!;
	if (!showcaseTitle) {
		return false;
	}

	showcaseTitle.firstChild!.after(
		' / ',
		<a href={String(buildUrl('stars'))}>Top repositories</a>
	);
}

features.add({
	id: __featureName__,
	description: 'Adds a link to the user’s most starred repositories.',
	screenshot: 'https://user-images.githubusercontent.com/1402241/48474026-43e3ae80-e82c-11e8-93de-159ad4c6f283.png',
	include: [
		features.isUserProfile
	],
	load: features.onAjaxedPages,
	init
});