21 lines
737 B
JavaScript
21 lines
737 B
JavaScript
const form = document.querySelector('form');
|
|
const input = document.querySelector('input');
|
|
|
|
form.addEventListener('submit', async event => {
|
|
event.preventDefault();
|
|
window.navigator.serviceWorker.register(__uv$config.sw, {
|
|
scope: __uv$config.prefix
|
|
}).then(() => {
|
|
let url = input.value.trim();
|
|
if (!isUrl(url)) url = 'https://www.google.com/search?q=' + url;
|
|
else if (!(url.startsWith('https://') || url.startsWith('http://'))) url = 'http://' + url;
|
|
|
|
|
|
window.location.href = __uv$config.prefix + __uv$config.encodeUrl(url);
|
|
});
|
|
});
|
|
|
|
function isUrl(val = ''){
|
|
if (/^http(s?):\/\//.test(val) || val.includes('.') && val.substr(0, 1) !== ' ') return true;
|
|
return false;
|
|
};
|