-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
commented-menu-item.js
31 lines (26 loc) · 995 Bytes
/
commented-menu-item.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
import {h} from 'dom-chef';
import select from 'select-dom';
import features from '../libs/features';
import {getUsername} from '../libs/utils';
import {isGlobalIssueSearch} from '../libs/page-detect';
function init() {
const username = getUsername();
const type = isGlobalIssueSearch() ? 'issue' : 'pr';
const commentedMenuItem = <a href={`${location.pathname}?q=is%3Aopen+archived%3Afalse+is%3A${type}+commenter%3A${username}`} class="subnav-item">Commented</a>;
if (!select.exists('.subnav-links .selected') && location.search.includes(`commenter%3A${username}`)) {
commentedMenuItem.classList.add('selected');
for (const tab of select.all(`.subnav-links a[href*="commenter%3A${username}"]`)) {
tab.href = tab.href.replace(`commenter%3A${username}`, '');
}
}
select('.subnav-links').append(commentedMenuItem);
}
features.add({
id: 'commented-menu-item',
include: [
features.isGlobalIssueSearch,
features.isGlobalPRSearch
],
load: features.onAjaxedPages,
init
});