-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
add-releases-tab.js
53 lines (45 loc) · 1.54 KB
/
add-releases-tab.js
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
45
46
47
48
49
50
51
52
53
import {h} from 'dom-chef';
import select from 'select-dom';
import * as icons from '../libs/icons';
import * as pageDetect from '../libs/page-detect';
import {registerShortcut} from './improve-shortcut-help';
const repoUrl = pageDetect.getRepoURL();
const repoKey = `${repoUrl}-releases-count`;
// Get as soon as possible, to have it ready before the first paint
let localCache = browser.storage.local.get(repoKey);
function appendReleasesCount(count) {
if (count) {
select('.reponav-releases').append(
<span class="Counter">{count}</span>
);
}
}
function updateReleasesCount() {
if (pageDetect.isRepoRoot()) {
const releasesCount = select('.numbers-summary a[href$="/releases"] .num');
if (releasesCount) {
localCache = {[repoKey]: Number(releasesCount.textContent)};
browser.storage.local.set(localCache);
}
}
}
export default async () => {
const releasesTab = (
<a href={`/${repoUrl}/releases`} class="reponav-item reponav-releases" data-hotkey="g r">
{icons.tag()}
<span> Releases </span>
</a>
);
registerShortcut('repos', 'g r', 'Go to Releases');
select('.reponav-dropdown').before(releasesTab);
updateReleasesCount();
appendReleasesCount((await localCache)[repoKey]);
if (pageDetect.isReleasesOrTags()) {
const selected = select('.reponav-item.selected');
if (selected) {
selected.classList.remove('js-selected-navigation-item', 'selected');
}
releasesTab.classList.add('js-selected-navigation-item', 'selected');
releasesTab.setAttribute('data-selected-links', 'repo_releases'); // Required for ajaxLoad
}
};