diff --git a/static/options/index.html b/static/options/index.html index b124e22..ed4f592 100644 --- a/static/options/index.html +++ b/static/options/index.html @@ -2,6 +2,7 @@ + Nebula @@ -9,7 +10,10 @@ - + + + + @@ -137,6 +141,13 @@ +
+

Bare location

+

Choose the location where a bare server is hosted.

+ +

+ +

Misc

@@ -176,6 +187,7 @@ if (cloakStored == "on") { } themeSelector.value = themeStored proxySel.value = proxyStored +document.getElementById("bareLocationInput").value = localStorage.getItem("_BareLocation") diff --git a/static/resources/appModules/database-manager.js b/static/resources/appModules/database-manager.js new file mode 100644 index 0000000..a2e035a --- /dev/null +++ b/static/resources/appModules/database-manager.js @@ -0,0 +1,19 @@ +const dbPromise = Ultraviolet.openDB('keyval-store', 1, { + upgrade(db) { + db.createObjectStore('keyval'); + }, +}); + +self.storage = { + async get(key) { + return (await dbPromise).get('keyval', key); + }, + + async set(key, val) { + return (await dbPromise).put('keyval', val, key); + }, + + async del(key) { + return (await dbPromise).delete('keyval', key); + }, +} \ No newline at end of file diff --git a/static/resources/appModules/selectBare.js b/static/resources/appModules/selectBare.js new file mode 100644 index 0000000..a494d81 --- /dev/null +++ b/static/resources/appModules/selectBare.js @@ -0,0 +1,74 @@ + +const dbPromise = Ultraviolet.openDB('keyval-store', 1, { + upgrade(db) { + db.createObjectStore('keyval'); + }, +}); + +self.storage = { + async get(key) { + return (await dbPromise).get('keyval', key); + }, + + async set(key, val) { + return (await dbPromise).put('keyval', val, key); + }, + + async del(key) { + return (await dbPromise).delete('keyval', key); + }, +} + +function getBareLocation() { + const location = storage.get("bareLocation"); + return location; +} + +function setBareLocation(location) { + if (/^http(s?):\/\//.test(location) || (location.includes('.') && val.substr(0, 1) !== ' ') || location.includes('/bare/')) { + storage.set("bareLocation", location); + return 'Bare is located at: ' + location; + } else { + console.log('Invalid Location provided, please provide a server in the format of http(s)://server.domain.com/'); + return 'Invalid Location provided'; + } +} + +function bareValidator(bareLocation) { + fetch(bareLocation) + .then((res) => res.json()) + .then((data) => { + if (data.project.name === "bare-server-node") { + return true; + } + + return false; + }) +} + + +window.addEventListener("load", () => { + const _loc = document.getElementById('bareLocationInput') + const indicator = document.getElementById('validIndicator') + if (bareValidator(_loc.value) === true) { + indicator.innerText = 'Connected to server: ' + _loc.value + indicator.style.color = '#42f851' + } else if (bareValidator(_loc.value) === false) { + indicator.innerText = 'Could not connect to server: ' + _loc.value + indicator.style.color = '#f45145bd' + } + + document.getElementById('bareLocationInput').addEventListener('keydown', function (event) { + if (event.key === 'Enter') { + if (bareValidator(_loc.value) === true) { + indicator.innerText = 'Connected to server: ' + _loc.value + indicator.style.color = '#42f851' + setBareLocation(_loc.value) + } else if (bareValidator(_loc.value) === false) { + indicator.innerText = 'Could not connect to server: ' + _loc.value + indicator.style.color = '#f45145bd' + } + } + }); + +}); \ No newline at end of file diff --git a/static/resources/nebulamain.js b/static/resources/nebulamain.js index 79fea68..1e9363f 100644 --- a/static/resources/nebulamain.js +++ b/static/resources/nebulamain.js @@ -19,6 +19,12 @@ function closeNav() { window.addEventListener("load", () => { // Register the service workers for Osana and Ultraviolet proxy protocols // This is a better method than registering onsubmit because this allows the ability to use proxied links on the main page. + + if (localStorage.getItem("_BareLocation") == undefined || localStorage.getItem("_BareLocation") == null) { + localStorage.setItem("_BareLocation", "/bare/") + } + + navigator.serviceWorker.register("./sw.js", { scope: "/service/", }) @@ -65,7 +71,10 @@ window.addEventListener("load", () => { return time } // initialize the time function + + if (window.location.pathname == "/"){ displayTime() + } // Link evaluation // This functions' purpose is to check a string of text (the argument) @@ -83,6 +92,7 @@ window.addEventListener("load", () => { const proxy = localStorage.getItem("proxy") || "uv" const inpbox = document.querySelector("form") // Display the "loading" indicators on the main page, looks much better than a static/still screen. + inpbox.addEventListener("submit", (event) => { // Prevents the default event tasks event.preventDefault() diff --git a/static/style/options.css b/static/style/options.css index 6a759f6..a890895 100644 --- a/static/style/options.css +++ b/static/style/options.css @@ -492,4 +492,38 @@ input:checked+label:after { label:active:after { width: 38px; +} + +.bareLocationInput { + border-style: solid !important; + border: var(--input-border-size) solid #5e18eb; + border-width: 0px; + border-radius: 6px; + background-color: #191724; + color: var(--input-text-color); + width: auto; + height: auto; + box-shadow: none !important; + outline: none; + text-align: center; + width: 220px; + font-size: 16px; + font-family: 'Roboto'; + height: 29px; + transition: 0.06s; +} +.bareLocationInput:hover { + border: var(--input-border-size) solid #5e18eb; + border-width: 1px; + border-radius: 6px; + +} + +.bareValidSignal{ + margin-top: -13px; + color: #f45145bd; + font-family: 'Ubuntu', sans-serif; + font-weight: lighter; + font-size: 13px; + text-align: center; } \ No newline at end of file diff --git a/static/sw.js b/static/sw.js index 02f4551..db39185 100644 --- a/static/sw.js +++ b/static/sw.js @@ -1,3 +1,6 @@ +importScripts('./uv/uv.bundle.js'); +importScripts('./resources/appModules/database-manager.js'); +importScripts('./uv/uv.config.js'); importScripts('./uv/uv.sw.js'); importScripts('./osana/osana.worker.js'); diff --git a/static/uv/uv.config.js b/static/uv/uv.config.js index efaadab..aa1c6bf 100644 --- a/static/uv/uv.config.js +++ b/static/uv/uv.config.js @@ -1,6 +1,8 @@ + + self.__uv$config = { prefix: '/service/go/', - bare: '/bare/', + bare: self.storage.get("bareLocation"), encodeUrl: Ultraviolet.codec.xor.encode, decodeUrl: Ultraviolet.codec.xor.decode, handler: '/uv/uv.handler.js', diff --git a/static/uv/uv.sw.js b/static/uv/uv.sw.js index 37b1d55..53c7486 100644 --- a/static/uv/uv.sw.js +++ b/static/uv/uv.sw.js @@ -1,5 +1,4 @@ -importScripts('/uv/uv.bundle.js'); -importScripts('/uv/uv.config.js'); + class UVServiceWorker extends EventEmitter { constructor(config = __uv$config) {