forked from tapio/live-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinjected.html
24 lines (24 loc) · 925 Bytes
/
injected.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<script>
// Code injected by live-server
(function() {
function refreshCSS() {
var sheets = document.getElementsByTagName("link");
for (var i = 0; i < sheets.length; ++i) {
var elem = sheets[i];
var rel = elem.rel;
if (elem.href && typeof rel != "string" || rel.length == 0 || rel.toLowerCase() == "stylesheet") {
var url = elem.href.replace(/(&|\?)_cacheOverride=\d+/, '');
elem.href = url + (url.indexOf('?') >= 0 ? '&' : '?') + '_cacheOverride=' + (new Date().valueOf());
}
}
}
var protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://';
var address = protocol + window.location.host + window.location.pathname + '/ws';
var socket = new WebSocket(address);
socket.onmessage = function(msg) {
if (msg.data == 'reload') window.location.reload()
else if (msg.data == 'refreshcss') refreshCSS();
};
console.log('Live reload enabled.');
})();
</script>