* Start the requestAnimationFrame UI rendering loop
()
| 258 | * Start the requestAnimationFrame UI rendering loop |
| 259 | */ |
| 260 | function startRenderingLoop() { |
| 261 | // Do these queries once to speed up the rendering itself |
| 262 | const serverSelector = document.querySelector("div.server-selector"); |
| 263 | const selectedServer = serverSelector.querySelector("#selected-server"); |
| 264 | const sponsor = serverSelector.querySelector("#sponsor"); |
| 265 | const startButton = document.querySelector("#start-button"); |
| 266 | const privacyWarning = document.querySelector("#privacy-warning"); |
| 267 | |
| 268 | const gauges = document.querySelectorAll("#download-gauge, #upload-gauge"); |
| 269 | const downloadProgress = document.querySelector("#download-gauge .progress"); |
| 270 | const uploadProgress = document.querySelector("#upload-gauge .progress"); |
| 271 | const downloadGauge = document.querySelector("#download-gauge .speed"); |
| 272 | const uploadGauge = document.querySelector("#upload-gauge .speed"); |
| 273 | const downloadText = document.querySelector("#download-gauge span"); |
| 274 | const uploadText = document.querySelector("#upload-gauge span"); |
| 275 | |
| 276 | const pingAndJitter = document.querySelectorAll(".ping, .jitter"); |
| 277 | const ping = document.querySelector("#ping"); |
| 278 | const jitter = document.querySelector("#jitter"); |
| 279 | const shareResults = document.querySelector("#share-results"); |
| 280 | const copyLink = document.querySelector("#copy-link"); |
| 281 | const resultsImage = document.querySelector("#results"); |
| 282 | |
| 283 | const buttonTexts = { |
| 284 | [INITIALIZING]: "Loading...", |
| 285 | [READY]: "Let's start", |
| 286 | [RUNNING]: "Abort", |
| 287 | [FINISHED]: "Restart", |
| 288 | }; |
| 289 | |
| 290 | // Show copy link button only if navigator.clipboard is available |
| 291 | copyLink.classList.toggle("hidden", !navigator.clipboard); |
| 292 | |
| 293 | function renderUI() { |
| 294 | // Make the main button reflect the current state |
| 295 | startButton.textContent = buttonTexts[testState.state]; |
| 296 | startButton.classList.toggle("disabled", testState.state === INITIALIZING); |
| 297 | startButton.classList.toggle("active", testState.state === RUNNING); |
| 298 | |
| 299 | // Disable the server selector while test is running |
| 300 | serverSelector.classList.toggle("disabled", testState.state === RUNNING); |
| 301 | |
| 302 | // Show selected server |
| 303 | if (testState.selectedServerDirty) { |
| 304 | const server = testState.speedtest.getSelectedServer(); |
| 305 | selectedServer.textContent = server.name; |
| 306 | if (server.sponsorName) { |
| 307 | if (server.sponsorURL) { |
| 308 | sponsor.innerHTML = `Sponsor: <a href="${server.sponsorURL}">${server.sponsorName}</a>`; |
| 309 | } else { |
| 310 | sponsor.textContent = `Sponsor: ${server.sponsorName}`; |
| 311 | } |
| 312 | } else { |
| 313 | sponsor.innerHTML = " "; |
| 314 | } |
| 315 | testState.selectedServerDirty = false; |
| 316 | } |
| 317 |