summaryrefslogtreecommitdiff
path: root/source/features/edit-comments-faster.tsx
blob: 875a536be5714f876859a7ed2fd6e25b267b6234 (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
import React from 'dom-chef';
import onetime from 'onetime';
import {observe} from 'selector-observer';
import PencilIcon from 'octicon/pencil.svg';
import * as pageDetect from 'github-url-detection';

import features from '.';

function init(): void {
	// Find editable comments first, then traverse to the correct position
	observe('.js-comment.unminimized-comment .js-comment-update:not(.rgh-edit-comment)', {
		add(comment) {
			comment.classList.add('rgh-edit-comment');

			comment.closest('.js-comment')!.querySelector('.js-comment-header-reaction-button')!.after(
				<button
					type="button"
					role="menuitem"
					className="timeline-comment-action btn-link js-comment-edit-button"
					aria-label="Edit comment"
				>
					<PencilIcon/>
				</button>
			);
		}
	});
}

void features.add(__filebasename, {
	include: [
		pageDetect.hasComments
	],
	init: onetime(init)
});