KC9UZR

HTML log viewer

Feb 1st, 2026
87
0
Never
8
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.91 KB | Source Code | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Log Viewer</title>
  6. <style>
  7.     body {
  8.         background-color: #111;
  9.         color: #0f0;
  10.         font-family: 'Cascadia Code', 'Courier New', monospace;
  11.         margin: 0;
  12.         padding: 20px;
  13.         white-space: pre-wrap;
  14.         word-wrap: break-word;
  15.         line-height: 1.4;
  16.     }
  17.     #log { margin: 0; }
  18. </style>
  19. </head>
  20. <body><pre id="log">Loading log…</pre>
  21.  
  22. <script>
  23. let lastModified = null;
  24. const logElement = document.getElementById('log');
  25.  
  26. async function loadLog() {
  27.     try {
  28.         // We add a timestamp (?t=...) to bypass aggressive browser caching
  29.         const response = await fetch('messages.log?t=' + Date.now(), {
  30.             cache: 'no-store'
  31.         });
  32.        
  33.         if (!response.ok) throw new Error('Network response was not ok');
  34.  
  35.         lastModified = response.headers.get('Last-Modified');
  36.         const text = await response.text();
  37.        
  38.         logElement.textContent = text;
  39.  
  40.         // Auto-scroll to bottom
  41.         window.scrollTo(0, document.body.scrollHeight);
  42.     } catch (err) {
  43.         logElement.textContent = 'Error loading log: ' + err.message;
  44.     }
  45. }
  46.  
  47. async function checkForUpdate() {
  48.     try {
  49.         const response = await fetch('messages.log?t=' + Date.now(), {
  50.             method: 'HEAD',
  51.             cache: 'no-store'
  52.         });
  53.        
  54.         const newModified = response.headers.get('Last-Modified');
  55.  
  56.         // Only reload if the header exists and has changed
  57.         if (newModified && newModified !== lastModified) {
  58.            console.log('Log updated, reloading...');
  59.             loadLog();
  60.         }
  61.     } catch (err) {
  62.         console.error('Error checking log update:', err);
  63.     }
  64. }
  65.  
  66. // Initial load
  67. loadLog();
  68.  
  69. // Check every 5 seconds (reduced from 10 for better responsiveness)
  70. setInterval(checkForUpdate, 5000);
  71. </script>
  72. </body>
  73. </html>
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment