summaryrefslogtreecommitdiff
path: root/source/features/easy-toggle-commit-messages.tsx
blob: f8838db24e76667fa2a04f74aced75f1c3be830b (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
import select from 'select-dom';
import delegate from 'delegate-it';
import * as pageDetect from 'github-url-detection';

import features from '.';

function toggleCommitMessage(event: delegate.Event<MouseEvent>): void {
	const elementClicked = event.target as HTMLElement;
	// The clicked element is not a button, a link or a popup ("Verified" badge, CI details, etc.)
	if (!elementClicked.closest('a, button, clipboard-copy, details')) {
		select('.ellipsis-expander', event.delegateTarget)?.dispatchEvent(
			new MouseEvent('click', {bubbles: true, altKey: event.altKey}),
		);
	}
}

function init(): Deinit {
	return delegate(document, '.js-commits-list-item', 'click', toggleCommitMessage);
}

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