|
4 | 4 | * when using the beans CLI development server. |
5 | 5 | */ |
6 | 6 |
|
7 | | -(function() { |
| 7 | +(function () { |
8 | 8 | 'use strict'; |
9 | 9 |
|
10 | 10 | // Configuration |
|
29 | 29 | z-index: 9999; |
30 | 30 | transition: background-color 0.3s ease; |
31 | 31 | `; |
32 | | - document.body.appendChild(indicator); |
| 32 | + if (document.body !== null) { |
| 33 | + document.body.appendChild(indicator); |
| 34 | + } |
33 | 35 | return indicator; |
34 | 36 | } |
35 | 37 |
|
|
44 | 46 | // Reload stylesheets to force CSS refresh |
45 | 47 | function reloadStylesheets() { |
46 | 48 | document.querySelectorAll('link[rel="stylesheet"]').forEach(link => { |
47 | | - const newHref = link.href.replace(/\?.*$/, '') + '?v=' + Date.now(); |
48 | | - link.href = newHref; |
| 49 | + try { |
| 50 | + const url = new URL(link.href); |
| 51 | + url.searchParams.set('v', Date.now()); |
| 52 | + link.href = url.toString(); |
| 53 | + } catch (e) { |
| 54 | + console.error('Failed to reload stylesheet:', link.href, e); |
| 55 | + } |
49 | 56 | }); |
50 | 57 | } |
51 | 58 |
|
|
62 | 69 | Window.lob_ws = new WebSocket(WS_URL); |
63 | 70 | } |
64 | 71 |
|
65 | | - Window.lob_ws.onopen = function() { |
| 72 | + Window.lob_ws.onopen = function () { |
66 | 73 | updateStatus(true); |
67 | 74 | }; |
68 | 75 |
|
69 | | - Window.lob_ws.onmessage = async function(event) { |
| 76 | + Window.lob_ws.onmessage = async function (event) { |
70 | 77 | try { |
71 | 78 | const data = JSON.parse(event.data); |
72 | 79 | if (data.type === 'file_changed') { |
|
103 | 110 | document.body.appendChild(newScript); |
104 | 111 | }); |
105 | 112 | } |
106 | | - }, 100); |
| 113 | + // Run any script here |
| 114 | + try { hljs.highlightAll(); } catch (e) { console.log(e); } |
| 115 | + }, 1); |
107 | 116 | } |
108 | 117 | } |
109 | 118 | } catch (e) { |
110 | 119 | console.log('Received:', event.data); |
111 | 120 | } |
112 | 121 | }; |
113 | 122 |
|
114 | | - Window.lob_ws.onclose = function() { |
| 123 | + Window.lob_ws.onclose = function () { |
115 | 124 | updateStatus(false); |
116 | 125 | scheduleReconnect(); |
117 | 126 | }; |
118 | 127 |
|
119 | | - Window.lob_ws.onerror = function(error) { |
| 128 | + Window.lob_ws.onerror = function (error) { |
120 | 129 | updateStatus(false); |
121 | 130 | scheduleReconnect(); |
122 | 131 | }; |
|
0 commit comments