diff options
| author | yum <yum.food.vr@gmail.com> | 2024-07-12 16:20:40 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2024-07-12 16:20:40 -0700 |
| commit | 6dc21f859e2443a80e7b46a5ed890a198af38ef9 (patch) | |
| tree | 3efae6548fd9ba5fb1fd6b4b131d42e28c2ad61f | |
| parent | 59578a647c9e259b6eb70cd9bee5428fae2bd0b9 (diff) | |
Replace hardcoded localhost with js magicv0.20.0
Use some js magic to deduce the hostname instead of hardcoding
localhost. If you used the browser source under 127.0.0.1, then
you'd get XSS blocked from making the ajax calls. This fixes that.
| -rw-r--r-- | BrowserSource/index.html | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/BrowserSource/index.html b/BrowserSource/index.html index d677eb6..573fdcc 100644 --- a/BrowserSource/index.html +++ b/BrowserSource/index.html @@ -60,22 +60,24 @@ </style> <body> <div id="content"></div> - <script> - function scrollToBottom() { - window.scrollTo(0, document.body.scrollHeight); - } + <script> + function scrollToBottom() { + window.scrollTo(0, document.body.scrollHeight); + } - function getTranscript() { - $.ajax({ - url: 'http://localhost:%PORT%/api/v0/transcript', - method: 'GET', - dataType: 'json', - success: function (data) { + function getTranscript() { + const host = window.location.hostname; + const port = window.location.port; + $.ajax({ + url: `http://${host}:${port}/api/v0/transcript`, + method: 'GET', + dataType: 'json', + success: function (data) { // dirty hack: create a bunch of invisible content to push the // transcript down the bottom var transcriptHtml = '<span class="transcript" style="opacity: 0">' + '___ '.repeat(128) + '</span>'; - data.commits.forEach(function (commit, index) { + data.commits.forEach(function (commit, index) { let age = data.ts - commit.ts; let min_age_s = 5.0; let max_age_s = 60.0; @@ -83,9 +85,9 @@ opacity = Math.max(0, opacity); opacity = Math.min(1, opacity); transcriptHtml += `<span class="transcript" style="opacity: ${opacity};">${commit.delta.trim() + ' '}</span>`; - }); + }); - // Append the preview with full opacity if it exists + // Append the preview with full opacity if it exists if (data.preview && data.preview.preview) { transcriptHtml += `<span class="preview" style="opacity: 1;">${data.preview.preview}</span>`; } @@ -97,16 +99,16 @@ $('#content').html(transcriptHtml + circleHtml); $('#content').css("background-color", "#22222280"); - }, - error: function (jqXHR, textStatus, errorThrown) { - console.error('Error getting transcript: ', textStatus, errorThrown); - } - }); - scrollToBottom(); - } + }, + error: function (jqXHR, textStatus, errorThrown) { + console.error('Error getting transcript: ', textStatus, errorThrown); + } + }); + scrollToBottom(); + } - setInterval(getTranscript, /*interval_ms=*/100); - </script> + setInterval(getTranscript, /*interval_ms=*/100); + </script> </body> </html> |
