-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathload-more-links-in-navbar.js
92 lines (78 loc) · 1.76 KB
/
load-more-links-in-navbar.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import {paths} from '../libs/paths';
function init(metadata) {
const navbar = document.querySelector('span.pagetop');
if (!navbar) {
return false;
}
const linkDetails = [
{
title: 'leaders',
description: 'Users with most karma'
},
{
title: 'best',
description: 'Highest-voted recent links'
},
{
title: 'active',
description: 'Most active current discussions'
},
{
title: 'newpoll',
description: 'Create a new poll'
},
{
title: 'bestcomments',
description: 'Highest-voted recent comments'
},
{
title: 'noobstories',
description: 'Submissions from new accounts'
},
{
title: 'noobcomments',
description: 'Comments from new accounts'
},
{
title: 'topcolors',
description: 'List of custom topcolors'
}
];
const moreLinkSepartor = document.createElement('span');
moreLinkSepartor.innerHTML = ' | ';
const moreLinksBtn = document.createElement('a');
moreLinksBtn.href = 'javascript:void(0)';
moreLinksBtn.innerHTML = 'more links >';
navbar.append(moreLinkSepartor, moreLinksBtn);
moreLinksBtn.addEventListener('click', () => {
moreLinksBtn.remove();
moreLinkSepartor.remove();
for (const link of linkDetails) {
if ('/' + link.title === metadata.path) {
continue;
}
const separatorText = document.createElement('span');
separatorText.innerHTML = ' | ';
const linkEl = document.createElement('a');
linkEl.href = link.title;
linkEl.innerHTML = link.title;
linkEl.title = link.description;
navbar.append(separatorText, linkEl);
}
});
return true;
}
const details = {
id: 'load-more-links-in-navbar',
pages: {
include: ['*'],
exclude: [
...paths.forms,
...paths.info
]
},
loginRequired: false,
runOnJobItems: true,
init
};
export default details;