summaryrefslogtreecommitdiff
path: root/source/features/link-to-prior-blame-line.tsx
blob: 3b9f31893203004a4fa434a99b40c1b75cb28a03 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import select from 'select-dom';
import * as pageDetect from 'github-url-detection';

import features from '.';

function init(): void {
	for (const link of select.all<HTMLAnchorElement>('.reblame-link')) {
		const lineNumber = link.closest('.blame-hunk')!.querySelector('.js-line-number[id]')!.id;
		link.hash = `#${lineNumber}`;
	}
}

void features.add({
	id: __filebasename,
	description: 'Preserves the current line on “View blame prior to this change” links.',
	screenshot: 'https://user-images.githubusercontent.com/1402241/60064482-26b47e00-9733-11e9-803c-c113ea612fbe.png'
}, {
	include: [
		pageDetect.isBlame
	],
	init
});