UNPKG

1.18 kBHTMLView Raw
1<!-- Code injected by live-server -->
2<script type="text/javascript">
3 // <![CDATA[ <-- For SVG support
4 if ('WebSocket' in window) {
5 (function() {
6 function refreshCSS() {
7 var sheets = [].slice.call(document.getElementsByTagName("link"));
8 var head = document.getElementsByTagName("head")[0];
9 for (var i = 0; i < sheets.length; ++i) {
10 var elem = sheets[i];
11 head.removeChild(elem);
12 var rel = elem.rel;
13 if (elem.href && typeof rel != "string" || rel.length == 0 || rel.toLowerCase() == "stylesheet") {
14 var url = elem.href.replace(/(&|\?)_cacheOverride=\d+/, '');
15 elem.href = url + (url.indexOf('?') >= 0 ? '&' : '?') + '_cacheOverride=' + (new Date().valueOf());
16 }
17 head.appendChild(elem);
18 }
19 }
20 var protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://';
21 var address = protocol + window.location.host + window.location.pathname + '/ws';
22 var socket = new WebSocket(address);
23 socket.onmessage = function(msg) {
24 if (msg.data == 'reload') window.location.reload();
25 else if (msg.data == 'refreshcss') refreshCSS();
26 };
27 console.log('Live reload enabled.');
28 })();
29 }
30 // ]]>
31</script>