Skip to content

Commit

Permalink
proxy backends (dynamic)
Browse files Browse the repository at this point in the history
  • Loading branch information
smartfoloo committed Oct 22, 2024
1 parent f0c48fa commit 90bdca0
Show file tree
Hide file tree
Showing 18 changed files with 2,161 additions and 37 deletions.
1,962 changes: 1,946 additions & 16 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"start": "node src/index.js"
},
"dependencies": {
"@nebula-services/dynamic": "^0.7.2-patch.2",
"@titaniumnetwork-dev/ultraviolet": "^3.2.7",
"@tomphttp/bare-server-node": "2.0.2",
"express": "^4.19.2"
Expand Down
30 changes: 30 additions & 0 deletions public/dynamic/dynamic.client.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions public/dynamic/dynamic.client.js.map

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions public/dynamic/dynamic.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
self.__dynamic$config = {
prefix: '/service/dynamic/',
encoding: 'xor',
mode: 'production', // development: zero caching, no minification, production: speed-oriented
logLevel: 0, // 0: none, 1: errors, 2: errors + warnings, 3: errors + warnings + info
bare: {
version: 2, // v3 is bad
path: '/bare/',
},
tab: {
title: 'Service',
icon: null,
ua: null,
},
assets: {
prefix: '/dynamic/',
files: {
handler: 'dynamic.handler.js',
client: 'dynamic.client.js',
worker: 'dynamic.worker.js',
config: 'dynamic.config.js',
inject: null,
}
},
block: [

]
};
30 changes: 30 additions & 0 deletions public/dynamic/dynamic.handler.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions public/dynamic/dynamic.handler.js.map

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions public/dynamic/dynamic.html.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions public/dynamic/dynamic.html.js.map

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions public/dynamic/dynamic.worker.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions public/dynamic/dynamic.worker.js.map

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,16 @@ <h2>Tab Cloaking</h2>
</div>

<div id="proxy" class="tab-content">
<div class="setting-card">
<h2>Proxy Backend</h2>
<p>Changing the proxy backend will make some sites faster but some may be slower. Ultraviolet is used by default.</p>
<div class="buttons">
<select id="proxy-backend" title="proxy-backend" onchange="setProxy(this.value)">
<option value="ultraviolet">Ultraviolet</option>
<option value="dynamic">Dynamic</option>
</select>
</div>
</div>
<div class="setting-card">
<h2>Search Engine</h2>
<p>Choose your search engine for our proxy.</p>
Expand Down Expand Up @@ -318,10 +328,11 @@ <h2>
</body>
<script src="uv/uv.bundle.js" defer></script>
<script src="uv/uv.config.js" defer></script>
<script src="uv/register-sw.js" defer></script>
<script src="dynamic/dynamic.worker.js" defer></script>
<script src="dynamic/dynamic.config.js" defer></script>
<script src="uv/search.js" defer></script>
<script src="uv/proxy.js" defer></script>
<script src="./js/system.js"></script>
<script src="./js/themes.js"></script>
<script src="/register-sw.js" defer></script>

</html>
10 changes: 10 additions & 0 deletions public/js/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ document.addEventListener('DOMContentLoaded', function () {
} else {
document.getElementById("searchEngine").value = "google";
}

if (localStorage.getItem("proxy")) {
document.getElementById("proxy-backend").value = localStorage.getItem("proxy");
} else {
document.getElementById("proxy-backend").value = "ultraviolet";
}
});

// Particles
Expand Down Expand Up @@ -400,6 +406,10 @@ function saveSearchEngine(selectedEngine) {
updateUvAddress()
}

function setProxy(proxy) {
localStorage.setItem('proxy', proxy);
}

// Settings page

function openTab(evt, tabName) {
Expand Down
4 changes: 2 additions & 2 deletions public/uv/register-sw.js → public/register-sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Distributed with Ultraviolet and compatible with most configurations.
*/
const stockSW = "./uv/sw.js";
const stockSW = "/sw.js";

/**
* List of hostnames that are allowed to run serviceworkers on http:
Expand All @@ -25,6 +25,6 @@ async function registerSW() {

// Ultraviolet has a stock `sw.js` script.
await navigator.serviceWorker.register(stockSW, {
scope: __uv$config.prefix,
scope: "/service",
});
}
19 changes: 19 additions & 0 deletions public/sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
importScripts('/dynamic/dynamic.config.js');
importScripts('/dynamic/dynamic.worker.js');
importScripts('/uv/uv.bundle.js');
importScripts('/uv/uv.config.js');
importScripts(__uv$config.sw || '/uv/uv.sw.js');

const uv = new UVServiceWorker();
const dynamic = new Dynamic();

self.addEventListener('fetch', event => {
if (event.request.url.startsWith(location.origin + '/service/dynamic/')) {
event.respondWith(dynamic.fetch(event));
console.log("Tried to fetch Dynamic");
}
if (event.request.url.startsWith(location.origin + '/service/uv/')) {
event.respondWith(uv.fetch(event));
console.log("Tried to fetch UV");
}
});
16 changes: 14 additions & 2 deletions public/uv/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ class UrlInfoHelper {

const helper = new UrlInfoHelper();

function getProxyUrl(url) {
const proxyType = localStorage.getItem('proxy');

if (proxyType === "dynamic") {
return "/service/dynamic/" + __uv$config.encodeUrl(url);
} else {
return "/service/uv/" + __uv$config.encodeUrl(url);
}

}

form.addEventListener("submit", async (event) => {
event.preventDefault();

Expand Down Expand Up @@ -80,7 +91,7 @@ form.addEventListener("submit", async (event) => {
tabsContainer.appendChild(newTab);

const newEmbed = document.createElement('iframe');
newEmbed.src = "/uv/service/" + __uv$config.encodeUrl(url);
newEmbed.src = getProxyUrl(url);
newEmbed.id = `${proxyTabId}-embed`;
newEmbed.classList.add('game-embed');
newEmbed.style.display = 'none';
Expand Down Expand Up @@ -133,6 +144,7 @@ function toggleEruda(frameId) {
};
}
}
*/

function openUV(url) {
Expand Down Expand Up @@ -168,7 +180,7 @@ function openUV(url) {
tabsContainer.appendChild(newTab);

const newEmbed = document.createElement('iframe');
newEmbed.src = "/uv/service/" + __uv$config.encodeUrl(url);
newEmbed.src = "/service/uv/" + __uv$config.encodeUrl(url);
newEmbed.id = `${proxyTabId}-embed`;
newEmbed.classList.add('game-embed');
newEmbed.style.display = 'none';
Expand Down
14 changes: 0 additions & 14 deletions public/uv/sw.js

This file was deleted.

2 changes: 1 addition & 1 deletion public/uv/uv.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This file overwrites the stock UV config.js

self.__uv$config = {
prefix: "/uv/service/",
prefix: "/service/uv/",
bare: "/bare/",
encodeUrl: Ultraviolet.codec.xor.encode,
decodeUrl: Ultraviolet.codec.xor.decode,
Expand Down

0 comments on commit 90bdca0

Please sign in to comment.