|
1 | 1 | <!DOCTYPE html> |
2 | 2 | <html> |
3 | | -<head> |
4 | | - <meta charset="UTF-8"> |
5 | | - <title>Diffs</title> |
6 | | -</head> |
7 | | -<body> |
8 | | - <h1>Git Diffs</h1> |
9 | | - <pre id="diff">Loading diffs...</pre> |
10 | | - <script> |
11 | | - fetch('/', { |
12 | | - headers: { |
13 | | - 'Accept': 'text/x-diff' |
| 3 | + <head> |
| 4 | + <meta charset="UTF-8" /> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 6 | + <title>Git Diffs</title> |
| 7 | + <link |
| 8 | + rel="stylesheet" |
| 9 | + href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/github.min.css" |
| 10 | + integrity="sha512-0aPQyyeZrWj9sCA46UlmWgKOP0mUipLQ6OZXu8l4IcAmD2u31EPEy9VcIMvl7SoAaKe8bLXZhYoMaE/in+gcgA==" |
| 11 | + crossorigin="anonymous" |
| 12 | + referrerpolicy="no-referrer" |
| 13 | + /> |
| 14 | + <link |
| 15 | + rel="stylesheet" |
| 16 | + type="text/css" |
| 17 | + href="https://cdn.jsdelivr.net/npm/diff2html@3.4.48/bundles/css/diff2html.min.css" |
| 18 | + integrity="sha384-iBvSlI3tNrrSIy7s6mvLg+5B2Z/QXbR4L0Pzg1nRf8zkXrz5JF316MLm2igMIpi2" |
| 19 | + crossorigin="anonymous" |
| 20 | + /> |
| 21 | + </head> |
| 22 | + <body> |
| 23 | + <div id="message"></div> |
| 24 | + <div id="diffs"></div> |
| 25 | + |
| 26 | + <script |
| 27 | + type="text/javascript" |
| 28 | + src="https://cdn.jsdelivr.net/npm/diff2html@3.4.48/bundles/js/diff2html-ui.min.js" |
| 29 | + integrity="sha384-99bAn+VpNpavq3FarkwuSuDPDHMeakTiNqxxz3ezwdGUr414srIXY3YmXjaAkYne" |
| 30 | + crossorigin="anonymous" |
| 31 | + ></script> |
| 32 | + <script> |
| 33 | + const message = document.getElementById("message"); |
| 34 | + const diffs = document.getElementById("diffs"); |
| 35 | + let currentDiff = ""; |
| 36 | + |
| 37 | + async function fetchAndRender() { |
| 38 | + try { |
| 39 | + const response = await fetch("/diffs", { |
| 40 | + headers: { Accept: "text/x-diff" }, |
| 41 | + }); |
| 42 | + const data = await response.text(); |
| 43 | + |
| 44 | + if (data !== currentDiff) { |
| 45 | + currentDiff = data; |
| 46 | + await new Diff2HtmlUI(diffs, currentDiff).draw(); |
| 47 | + message.innerHTML = ""; |
| 48 | + } |
| 49 | + } catch (error) { |
| 50 | + message.innerHTML = |
| 51 | + "<div>Error fetching diffs: " + |
| 52 | + error.message + |
| 53 | + "</div>"; |
| 54 | + } |
14 | 55 | } |
15 | | - }) |
16 | | - .then(response => response.text()) |
17 | | - .then(data => { |
18 | | - document.getElementById('diff').textContent = data || 'No changes'; |
19 | | - }) |
20 | | - .catch(error => { |
21 | | - document.getElementById('diff').textContent = 'Error loading diffs: ' + error; |
22 | | - }); |
23 | | - </script> |
24 | | -</body> |
| 56 | + |
| 57 | + fetchAndRender(); |
| 58 | + setInterval(fetchAndRender, 10000); |
| 59 | + </script> |
| 60 | + </body> |
25 | 61 | </html> |
0 commit comments