Skip to content

Commit

Permalink
gpr
Browse files Browse the repository at this point in the history
  • Loading branch information
bachwebsite committed Mar 24, 2024
1 parent f0d6d3a commit 25db41c
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion public/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
"use strict";

/**
* @type {HTMLFormElement}
*/
const form = document.getElementById("uv-form");

/**
* @type {HTMLInputElement}
*/
const address = document.getElementById("uv-address");

/**
* @type {HTMLInputElement}
*/
const searchEngine = document.getElementById("uv-search-engine");

/**
* @type {HTMLParagraphElement}
*/
const error = document.getElementById("uv-error");

/**
* @type {HTMLPreElement}
*/
Expand All @@ -28,7 +33,8 @@ form.addEventListener("submit", async (event) => {
} catch (err) {
error.textContent = "Failed to register service worker.";
errorCode.textContent = err.toString();
throw err;
console.error(err); // Log the error for debugging purposes
return; // Return early to prevent further execution
}

const url = search(address.value, searchEngine.value);
Expand All @@ -37,3 +43,30 @@ form.addEventListener("submit", async (event) => {
frame.style.display = "block";
frame.src = __uv$config.prefix + __uv$config.encodeUrl(url);
});

/**
* Function to register the service worker
*/
async function registerSW() {
if ('serviceWorker' in navigator) {
try {
await navigator.serviceWorker.register('/service-worker.js');
console.log('Service worker registered successfully');
} catch (error) {
throw new Error('Failed to register service worker: ' + error.message);
}
} else {
throw new Error('Service workers are not supported in this browser.');
}
}

/**
* Function to perform search
* @param {string} addressValue
* @param {string} searchEngineValue
* @returns {string} The URL for the search
*/
function search(addressValue, searchEngineValue) {
// Implement your search logic here
return 'https://' + searchEngineValue + '.com/search?q=' + encodeURIComponent(addressValue);
}

0 comments on commit 25db41c

Please sign in to comment.