-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmenubuttons.js
More file actions
37 lines (29 loc) · 894 Bytes
/
menubuttons.js
File metadata and controls
37 lines (29 loc) · 894 Bytes
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
import eventManager from './eventManager.js';
import style from './style.js';
let menu;
export default function addMenuButton(name, url) {
if (!menu) return false;
if (!name) throw new Error('Menu button must have a name');
const el = document.createElement('li');
const a = document.createElement('a');
a.classList.add('click');
a.innerHTML = name;
if (url) {
a.rel = 'noreferrer';
a.href = url;
}
el.append(a);
menu.append(el);
return el;
}
eventManager.on(':preload', () => {
menu = document.querySelector('ul.dropdown-menu[role="menu"]');
if (!menu) return;
style.add('.click {cursor: pointer;}');
const divider = document.createElement('li');
divider.classList.add('divider');
const header = document.createElement('li');
header.classList.add('dropdown-header');
header.textContent = 'UnderScript';
menu.append(divider, header);
});