summaryrefslogtreecommitdiff
path: root/source/features/prevent-duplicate-pr-submission.tsx
blob: 61dfb2726ddddd90babb8ed1ff9e83d3d62cff64 (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
import delegate from 'delegate-it';
import * as pageDetect from 'github-url-detection';

import features from '.';

let previousSubmission = 0;

function preventSubmit(event: delegate.Event): void {
	if (Date.now() - previousSubmission < 1000) {
		event.preventDefault();
	}

	previousSubmission = Date.now();
}

function init(): Deinit {
	return delegate(document, '#new_pull_request', 'submit', preventSubmit);
}

void features.add(import.meta.url, {
	include: [
		pageDetect.isCompare,
	],
	init,
});