This repository was archived by the owner on Jun 21, 2023. It is now read-only.
forked from refined-github/refined-github
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathadd-releases-tab.js
More file actions
51 lines (40 loc) · 1.32 KB
/
add-releases-tab.js
File metadata and controls
51 lines (40 loc) · 1.32 KB
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
import select from 'select-dom';
import {h} from 'dom-chef';
import * as icons from '../libs/icons';
import * as pageDetect from '../libs/page-detect';
const repoUrl = pageDetect.getRepoURL();
function appendReleasesCount(count) {
if (!count) {
return;
}
select('.reponav-releases').append(<span class="Counter">{count}</span>);
}
async function cacheReleasesCount() {
const releasesCountCacheKey = `${repoUrl}-releases-count`;
if (pageDetect.isRepoRoot()) {
const releasesCount = select('.numbers-summary a[href$="/releases"] .num').textContent.trim();
appendReleasesCount(releasesCount);
browser.storage.local.set({[releasesCountCacheKey]: releasesCount});
} else {
const items = await browser.storage.local.get(releasesCountCacheKey);
appendReleasesCount(items[releasesCountCacheKey]);
}
}
export default () => {
if (select.exists('.reponav-releases')) {
return;
}
const releasesTab = (
<a href={`/${repoUrl}/releases`} class="reponav-item reponav-releases" data-hotkey="g r">
{icons.tag()}
<span> Releases </span>
</a>
);
select('.reponav-dropdown').before(releasesTab);
cacheReleasesCount();
if (pageDetect.isReleases()) {
releasesTab.classList.add('js-selected-navigation-item', 'selected');
select('.reponav-item.selected')
.classList.remove('js-selected-navigation-item', 'selected');
}
};