summaryrefslogtreecommitdiff
path: root/source/features/action-used-by-link.tsx
blob: 6c3d0bc45e6079a1dc16364b9c8482796a68e665 (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 {$} from 'select-dom';
import {SearchIcon} from '@primer/octicons-react';
import * as pageDetect from 'github-url-detection';

import features from '../feature-manager.js';
import selectHas from '../helpers/select-has.js';

function init(): void {
	const actionRepo = selectHas('aside a:has(.octicon-repo)')!
		.pathname
		.slice(1);

	const actionURL = new URL('search', location.origin);
	actionURL.search = new URLSearchParams({
		q: `${actionRepo} path:.github/workflows/ language:YAML`,
		type: 'Code',
		s: 'indexed',
		o: 'desc',
	}).toString();

	$('.d-block.mb-2[href^="/contact"]')!.after(
		<a href={actionURL.href} className="d-block mb-2">
			<SearchIcon width={14} className="color-fg-default mr-2"/>Usage examples
		</a>,
	);
}

void features.add(import.meta.url, {
	include: [
		pageDetect.isMarketplaceAction,
	],
	awaitDomReady: true,
	deduplicate: 'has-rgh',
	init,
});