summaryrefslogtreecommitdiff
path: root/source/features/remove-checks-tab.tsx
blob: dcf26a66fd185f0dd6ed0922d5a56192bb940868 (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 select from 'select-dom';
import * as pageDetect from 'github-url-detection';

import features from '.';

function init(): void {
	// Only remove the tab if it's not the current page and if it has 0 checks
	const checksCounter = select('.tabnav-tab[href$="/checks"]:not(.selected) .Counter');

	if (checksCounter?.textContent!.trim() === '0') {
		checksCounter?.parentElement!.remove();
	}
}

void features.add({
	id: __filebasename,
	description: 'Hides the `Checks` tab if it’s empty, unless you’re the owner.',
	screenshot: false
}, {
	include: [
		pageDetect.isPR
	],
	exclude: [
		pageDetect.canUserEditRepo
	],
	init
});