summaryrefslogtreecommitdiff
path: root/source/features/patch-diff-links.tsx
blob: 027eb5e41670945f031d6826da021f66cc0766c7 (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
import './patch-diff-links.css';
import React from 'dom-chef';
import select from 'select-dom';
import features from '../libs/features';
import {isPRCommit} from '../libs/page-detect';

function init(): void {
	let commitUrl = location.pathname.replace(/\/$/, '');

	if (isPRCommit()) {
		commitUrl = commitUrl.replace(/\/pull\/\d+\/commits/, '/commit');
	}

	select('.commit-meta > :last-child')!.append(
		<span className="sha-block patch-diff-links">
			<a href={`${commitUrl}.patch`} className="sha">patch</a>
			{ ' ' /* Workaround for: JSX eats whitespace between elements */ }
			<a href={`${commitUrl}.diff`} className="sha">diff</a>
		</span>
	);
}

features.add({
	id: __featureName__,
	description: 'Adds links to `.patch` and `.diff` files in commits.',
	screenshot: 'https://cloud.githubusercontent.com/assets/737065/13605562/22faa79e-e516-11e5-80db-2da6aa7965ac.png',
	include: [
		features.isCommit
	],
	load: features.onAjaxedPages,
	init
});