blob: 3c934d5eb79c2e29606a8dcdfc354be61a0e4be9 (
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
35
36
37
38
39
40
41
42
43
44
|
import React from 'dom-chef';
import select from 'select-dom';
import fileIcon from 'octicon/file.svg';
import features from '../libs/features';
import {groupSiblings} from '../libs/group-buttons';
function init(): void | false {
const breadcrumb = select('.breadcrumb');
if (!breadcrumb) {
// Probably looking at the base /commits/<branch> page, not a subfolder or file.
return false;
}
// Extract the file path from the breadcrumb. Aware of branch names that contain slashes
const path = breadcrumb.textContent!.trim().replace(/^History for [^/]+/, '');
for (const rootLink of select.all<HTMLAnchorElement>('[aria-label="Browse the repository at this point in the history"]')) {
// `rootLink.pathname` points to /tree/ but GitHub automatically redirects to /blob/ when the path is of a file
rootLink.before(
<a
href={rootLink.pathname + path}
className="btn btn-outline tooltipped tooltipped-sw"
aria-label="See object at this point in the history"
>
{fileIcon()}
</a>
);
rootLink.closest<HTMLElement>('.commit-links-cell')!.style.width = 'auto';
groupSiblings(rootLink);
}
}
features.add({
id: __featureName__,
description: 'Adds links to the file itself in a file’s commit list.',
screenshot: 'https://user-images.githubusercontent.com/22439276/57195061-b88ddf00-6f6b-11e9-8ad9-13225d09266d.png',
include: [
features.isRepoCommitList
],
load: features.onAjaxedPages,
init
});
|