forked from plibither8/refined-hacker-news
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile-links-dropdown.js
92 lines (78 loc) · 1.78 KB
/
profile-links-dropdown.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 {isClickModified} from '../libs/utils';
import {paths} from '../libs/paths';
async function init(metadata) {
const {user} = metadata;
const links = [
{
title: 'profile',
path: `user?id=${user}`
},
{
title: 'submissions',
path: `submitted?id=${user}`
},
{
title: 'comments',
path: `threads?id=${user}`
},
{
title: 'hidden',
path: 'hidden'
},
{
title: 'upvoted submissions',
path: `upvoted?id=${user}`
},
{
title: 'upvoted comments',
path: `upvoted?id=${user}&comments=t`
},
{
title: 'favorite submissions',
path: `favorites?id=${user}`
},
{
title: 'favorite comments',
path: `favorites?id=${user}&comments=t`
}
];
const dropdownEl = document.createElement('div');
const targetCell = document.querySelectorAll('span.pagetop')[1];
const userLink = document.querySelector('a#me');
if (!userLink) {
return false;
}
userLink.innerHTML += ' ▾';
dropdownEl.classList.add('__rhn__no-display', '__rhn__profile-dropdown');
dropdownEl.style.background = metadata.topcolor;
let state = 0;
for (const link of links) {
const anchorEl = document.createElement('a');
anchorEl.href = link.path;
anchorEl.innerHTML = link.title;
dropdownEl.append(anchorEl);
}
targetCell.append(dropdownEl);
userLink.addEventListener('click', event => {
if (isClickModified(event)) {
return;
}
event.preventDefault();
dropdownEl.style.left = userLink.getBoundingClientRect().left + 'px';
dropdownEl.classList.toggle('__rhn__no-display');
userLink.innerHTML = `${user} ${state ? '▾' : '▴'}`;
state = 1 - state;
});
return true;
}
const details = {
id: 'profile-link-dropdown',
pages: {
include: ['*'],
exclude: paths.info
},
loginRequired: true,
runOnJobItems: true,
init
};
export default details;