Skip to content

Commit

Permalink
chore(#194): readability
Browse files Browse the repository at this point in the history
  • Loading branch information
jannis-baum committed Dec 17, 2024
1 parent 822a2a8 commit bf470ff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/routes/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,12 @@ router.get(/.*/, async (req: Request, res: Response) => {
${body}
</div>
</body>
<script>
window.VIV_PORT = "${config.port}";
window.VIV_PATH = "${urlToPath(req.path)}";
</script>
${config.scripts ? `<script type="text/javascript">${config.scripts}</script>` : ''}
<script type="module" src="/static/client.mjs"></script>
</html>
`);
Expand Down
9 changes: 9 additions & 0 deletions static/client.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* --------------------------------------------------------------------------
* MERMAID ------------------------------------------------------------------ */

import mermaid from '/static/mermaid/mermaid.esm.min.mjs';

const darkModePreference = window.matchMedia('(prefers-color-scheme: dark)');
Expand All @@ -17,6 +20,9 @@ try {
} catch {}
}

/* --------------------------------------------------------------------------
* WEBSOCKET COMMUNICATION WITH SERVER -------------------------------------- */

const ws = new WebSocket(`ws://localhost:${window.VIV_PORT}`);

ws.addEventListener('open', () => {
Expand All @@ -36,6 +42,7 @@ ws.addEventListener('message', (event) => {
await mermaid.run({ querySelector: '.mermaid' });
})();
break;

case 'SCROLL':
let line = parseInt(value);
while (line) {
Expand All @@ -50,9 +57,11 @@ ws.addEventListener('message', (event) => {
line -= 1;
}
break;

case 'RELOAD':
window.location.reload();
break;

case 'PRINT':
console.log(value);
break;
Expand Down

0 comments on commit bf470ff

Please sign in to comment.