mirror of
https://github.com/morris/vanilla-todo.git
synced 2025-08-18 11:51:20 +02:00
don't connect to dev server when automated
This commit is contained in:
@@ -1,35 +1,37 @@
|
||||
/* eslint-disable no-console */
|
||||
const socket = new WebSocket(
|
||||
`${(location.protocol === 'http:' ? 'ws://' : 'wss://') + location.host}/`,
|
||||
);
|
||||
if (!navigator.webdriver) {
|
||||
const socket = new WebSocket(
|
||||
`${(location.protocol === 'http:' ? 'ws://' : 'wss://') + location.host}/`,
|
||||
);
|
||||
|
||||
socket.addEventListener('message', (message) => {
|
||||
if (!message.data) return;
|
||||
socket.addEventListener('message', (message) => {
|
||||
if (!message.data) return;
|
||||
|
||||
const data = JSON.parse(message.data);
|
||||
const data = JSON.parse(message.data);
|
||||
|
||||
let reload = true;
|
||||
let reload = true;
|
||||
|
||||
// hot reload stylesheets
|
||||
document.querySelectorAll('link[rel=stylesheet]').forEach((el) => {
|
||||
if (el.getAttribute('href') === data.url) {
|
||||
el.setAttribute('href', data.url);
|
||||
reload = false;
|
||||
}
|
||||
// hot reload stylesheets
|
||||
document.querySelectorAll('link[rel=stylesheet]').forEach((el) => {
|
||||
if (el.getAttribute('href') === data.url) {
|
||||
el.setAttribute('href', data.url);
|
||||
reload = false;
|
||||
}
|
||||
});
|
||||
|
||||
// hot reload images
|
||||
document.querySelectorAll('img').forEach((el) => {
|
||||
if (el.getAttribute('src') === data.url) {
|
||||
el.setAttribute('src', data.url);
|
||||
reload = false;
|
||||
}
|
||||
});
|
||||
|
||||
// otherwise, reload page
|
||||
if (reload) location.reload();
|
||||
});
|
||||
|
||||
// hot reload images
|
||||
document.querySelectorAll('img').forEach((el) => {
|
||||
if (el.getAttribute('src') === data.url) {
|
||||
el.setAttribute('src', data.url);
|
||||
reload = false;
|
||||
}
|
||||
socket.addEventListener('close', () => {
|
||||
console.warn('Development server disconnected');
|
||||
});
|
||||
|
||||
// otherwise, reload page
|
||||
if (reload) location.reload();
|
||||
});
|
||||
|
||||
socket.addEventListener('close', () => {
|
||||
console.warn('Development server disconnected');
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user