-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpage.js
43 lines (36 loc) · 1.22 KB
/
page.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
(function () {
const element = document.querySelectorAll('a[name]');
element.forEach(el => {
el.setAttribute('id', el.getAttribute('name'));
});
hljs.highlightAll();
const vscode = acquireVsCodeApi();
let message = {
command: 'update',
file: '',
line: 1,
isEmpty: false,
isUntitled: false
};
const header = /** @type {HTMLElement} */ (document.getElementsByTagName('header')[0]);
const btnReload = /** @type {HTMLElement} */ (document.getElementById('btnReload'));
btnReload.addEventListener('click', () => {
vscode.postMessage({
command: 'reload',
file: message.file,
line: message.line,
isUntitled: message.isUntitled
});
});
window.addEventListener('message', event => {
message = event.data; // The json data that the extension sent
switch (message.command) {
case 'update': {
const css = (message.file && message.file.length > 0) && !message.isEmpty ? 'display-flex' : 'display-none';
header.classList.length = 0;
header.classList.add(css);
break;
}
}
});
}());