-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathensuite-nav.js
28 lines (24 loc) · 944 Bytes
/
ensuite-nav.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
"use strict";(()=>{
const ensuiteUrl = Object.assign(new URL(location.href), { protocol: 'ws', hash: '' }).href
console.log('Connecting to reloader at', ensuiteUrl)
const ensuiteSocket = new WebSocket(ensuiteUrl)
ensuiteSocket.addEventListener('message', message => {
switch (message.data) {
case 'ready': console.info('Reloader ready'); ensuiteSocket.send('ready'); break;
case 'reload': console.info('Reloading'); break;
}
})
document.querySelectorAll('a[href]').forEach(async element=>{
if (element.href.startsWith('mailto:')) return
try {
await fetch(element.href, { method: 'HEAD', mode: 'no-cors' })
} catch (e) {
console.warn(e)
element.style.background = 'red'
}
})
document.body.appendChild(Object.assign(document.createElement('nav'), {
className: 'ensuite-navigator',
innerHTML: document.querySelector('template[name=ensuite]').innerHTML,
}))
})()