vendor/github.com/go-rod/rod/lib/assets/monitor-page.html

103 lines · 2458 bytes

  1<html>
  2  <head>
  3    <style>
  4      body {
  5        margin: 0;
  6        background: #2d2c2f;
  7        color: #ffffff;
  8      }
  9      .navbar {
 10        font-family: sans-serif;
 11        border-bottom: 1px solid #1413158c;
 12        display: flex;
 13        flex-direction: row;
 14      }
 15      .error {
 16        color: #ff3f3f;
 17        background: #3e1f1f;
 18        border-bottom: 1px solid #1413158c;
 19        display: none;
 20        padding: 10px;
 21        margin: 0;
 22      }
 23      input {
 24        background: transparent;
 25        color: white;
 26        border: none;
 27        border: 1px solid #4f475a;
 28        border-radius: 3px;
 29        padding: 5px;
 30        margin: 5px;
 31      }
 32      .title {
 33        flex: 2;
 34      }
 35      .url {
 36        flex: 5;
 37      }
 38      .rate {
 39        flex: 1;
 40      }
 41    </style>
 42  </head>
 43  <body>
 44    <div class="navbar">
 45      <input
 46        type="text"
 47        class="title"
 48        title="title of the remote page"
 49        readonly
 50      />
 51      <input type="text" class="url" title="url of the remote page" readonly />
 52      <input
 53        type="number"
 54        class="rate"
 55        value="0.5"
 56        min="0"
 57        step="0.1"
 58        title="refresh rate (second)"
 59      />
 60    </div>
 61    <pre class="error"></pre>
 62    <img class="screen" />
 63  </body>
 64  <script>
 65    const id = location.pathname.split('/').slice(-1)[0]
 66    const elImg = document.querySelector('.screen')
 67    const elTitle = document.querySelector('.title')
 68    const elUrl = document.querySelector('.url')
 69    const elRate = document.querySelector('.rate')
 70    const elErr = document.querySelector('.error')
 71
 72    document.title = `Rod Monitor - ${id}`
 73
 74    async function update() {
 75      const res = await fetch(`/api/page/${id}`)
 76      const info = await res.json()
 77      elTitle.value = info.title
 78      elUrl.value = info.url
 79
 80      await new Promise((resolve, reject) => {
 81        const now = new Date()
 82        elImg.src = `/screenshot/${id}?t=${now.getTime()}`
 83        elImg.style.maxWidth = innerWidth + 'px'
 84        elImg.onload = resolve
 85        elImg.onerror = () => reject(new Error('error loading screenshots'))
 86      })
 87    }
 88
 89    async function mainLoop() {
 90      try {
 91        await update()
 92        elErr.attributeStyleMap.delete('display')
 93      } catch (err) {
 94        elErr.style.display = 'block'
 95        elErr.textContent = err + ''
 96      }
 97
 98      setTimeout(mainLoop, parseFloat(elRate.value) * 1000)
 99    }
100
101    mainLoop()
102  </script>
103</html>