updates comments in main script

This commit is contained in:
James Tomasino 2023-02-27 13:29:02 +00:00
parent 610f75c97a
commit 78ab2ea1b4
1 changed files with 11 additions and 14 deletions

25
main.js
View File

@ -8,7 +8,6 @@ var wobblyGo
var wobblySpinner
var startpage = 'gemini://tildeverse.org/'
var xhr
var xhrTimeout
function geminiInit() {
// Store references to all our DOM elements
@ -82,35 +81,33 @@ function geminiGo(fromURL) {
pushState()
}
// Enable throbber to indicate page loading
wobblySpinner.classList.add('active')
// If any unfinished xhrs, abort them and begin anew
if (xhr) {
xhr.abort()
}
// Send gemini request to cgi and populate result into wobbly window
xhrTimout = setTimeout(stopXHR, 5000)
// Setup gemini request for CGI
xhr = new XMLHttpRequest()
xhr.open( "GET", "browser.cgi?" + url )
xhr.onload = function () {
// If success: show page contents and clear throbber
xhr.onload = () => {
const body = xhr.responseText
wobblyWindow.innerHTML = body
wobblySpinner.classList.remove('active')
clearTimeout(xhrTimeout)
}
xhr.onerror = function () {
console.error(xhr.statusText)
// If error: show error contents on page
xhr.onerror = () => {
wobblySpinner.classList.remove('active')
wobblyWindow.innerHTML = `<h1>Something went wrong</h1><p>Error reported:</p><p>${xhr.statusText}</p>`
clearTimeout(xhrTimeout)
}
xhr.send(null)
}
function stopXHR() {
xhr.abort()
wobblySpinner.classList.remove('active')
wobblyWindow.innerHTML = `<h1>Request Timeout</h1><p>Your request was taking too long so it has been cancelled.</p>`
// Initiate request
xhr.send(null)
}
// Simple show/hide of help block