summaryrefslogtreecommitdiff
path: root/source/features/preserve-whitespace-option-in-nav.tsx
blob: cef561afdc4e954a2f0c5a407aeb83f74f8a217d (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
import select from 'select-dom';
import * as pageDetect from 'github-url-detection';

import features from '.';

function init(): void {
	for (const a of select.all<HTMLAnchorElement>('[data-hotkey="p"], [data-hotkey="n"]')) {
		const linkUrl = new URLSearchParams(a.search);
		linkUrl.set('w', '1');
		a.search = String(linkUrl);
	}
}

void features.add({
	id: __filebasename,
	description: 'Preserves the "ignore whitespace" setting when navigating with Next/Previous in PR review mode.',
	screenshot: false
}, {
	include: [
		pageDetect.isRepo
	],
	exclude: [
		() => new URLSearchParams(location.search).get('w') !== '1'
	],
	init
});