I need to push whatever I have done

This commit is contained in:
MotorTruck1221 2024-10-25 15:16:15 -06:00
parent 4d4ebf2d09
commit ff7eb81e87
No known key found for this signature in database
GPG key ID: 08F417E2B8B61EA4
9 changed files with 118 additions and 69 deletions

View file

@ -0,0 +1,10 @@
function gyatt2() {
return {
host: 'example.com',
html: '<script>console.error("GYATT... 2")</script>',
injectTo: 'head'
}
}
//We need to return the refrence to the function and NOT the function itself
self.entryFunc = gyatt2;

View file

@ -0,0 +1,10 @@
function gyatt() {
return {
host: 'example.com',
html: '<script>console.error("GYATT")</script>',
injectTo: 'head'
}
}
//We need to return the refrence to the function and NOT the function itself
self.entryFunc = gyatt;

View file

@ -5,27 +5,21 @@ const uv = new UVServiceWorker();
//where we handle our plugins!!! //where we handle our plugins!!!
self.addEventListener("message", function(event) { self.addEventListener("message", function(event) {
//console.log(event.data); console.log(event.data);
if (uv.config.inject === undefined) {
uv.config.inject = []; uv.config.inject = [];
}
//loop over the required data (we don't verify here as types will take care of us :D) //loop over the required data (we don't verify here as types will take care of us :D)
event.data.forEach((data) => { event.data.forEach((data) => {
if (data.remove) { if (data.remove) {
if (uv.config.inject.find(({ host }) => host === data.host)) {
const idx = uv.config.inject.indexOf(data.host); const idx = uv.config.inject.indexOf(data.host);
uv.config.inject.splice(idx, 1); uv.config.inject.splice(idx, 1);
} }
}
else { else {
if (!uv.config.inject.find(({ host }) => host === data.host)) {
uv.config.inject.push({ uv.config.inject.push({
host: data.host, host: data.host,
html: data.html, html: data.html,
injectTo: data.injectTo injectTo: data.injectTo
}); });
} }
}
}); });
console.log(uv.config.inject); console.log(uv.config.inject);
}); });

View file

@ -73,6 +73,28 @@ async function setupDB(db: ModelStatic<CatalogModel>) {
tags: ["Theme", "Simple", "Dark", "Retro"], tags: ["Theme", "Simple", "Dark", "Retro"],
payload: "retro.css", payload: "retro.css",
type: "theme", type: "theme",
},
{
package_name: "com.nebula.test",
title: 'GYATT',
image: 'gyatt.png',
author: 'NBS',
version: '0.0.0',
description: 'gyatt',
tags: [],
payload: 'index.js',
type: 'plugin'
},
{
package_name: "com.nebula.test-2",
title: 'GYATT...2',
image: 'gyatt.png',
author: 'NBS',
version: '0.0.0',
description: 'gyatt',
tags: [],
payload: 'index.js',
type: 'plugin'
} }
]; ];
const dbItems = await db.findAll(); const dbItems = await db.findAll();

View file

@ -11,17 +11,15 @@ export const prerender = true;
<iframe id="chango" class="w-full h-full"></iframe> <iframe id="chango" class="w-full h-full"></iframe>
</Layout> </Layout>
<script> <script>
import { initSw, setTransport } from "@utils/registerSW.ts"; //../../utils/registerSW.ts import { initSw, loadProxyScripts, setTransport } from "@utils/registerSW.ts"; //../../utils/registerSW.ts
import { Settings } from "@utils/settings/index"; import { Settings } from "@utils/settings/index";
import { pageLoad } from "@utils/events"; import { pageLoad } from "@utils/events";
pageLoad(async () => { pageLoad(async () => {
const iframe = document.getElementById("chango") as HTMLIFrameElement; const iframe = document.getElementById("chango") as HTMLIFrameElement;
if (iframe) { const conn = await loadProxyScripts();
initSw().then((init) => { await setTransport(conn, localStorage.getItem(Settings.ProxySettings.transport) as string);
setTransport(init.conn, localStorage.getItem(Settings.ProxySettings.transport) as string).then(async () => { await initSw().then(() => {
iframe.src = __uv$config!.prefix + __uv$config.encodeUrl!("https://radon.games"); if (iframe) return iframe.src = __uv$config!.prefix + __uv$config.encodeUrl!("https://radon.games");
}); });
}); });
}
});
</script> </script>

View file

@ -46,21 +46,18 @@ import { VERSION } from "astro:env/client";
</div> </div>
</Layout> </Layout>
<script> <script>
import { initSw, setTransport } from "@utils/registerSW.ts"; //../../utils/registerSW.ts import { initSw, setTransport, loadProxyScripts } from "@utils/registerSW.ts"; //../../utils/registerSW.ts
import { pageLoad } from "@utils/events"; import { pageLoad } from "@utils/events";
import { RammerheadEncode } from "@rubynetwork/rammerhead-browser"; import { RammerheadEncode } from "@rubynetwork/rammerhead-browser";
import { SupportedSites } from "@utils/siteSupport"; import { SupportedSites } from "@utils/siteSupport";
import { import {
WispServerURLS,
SearchEngines, SearchEngines,
Settings, Settings,
cloak, cloak,
settings settings
} from "@utils/settings/index"; } from "@utils/settings/index";
import { search } from "@utils/search.ts"; //../../utils/search.ts import { search } from "@utils/search.ts"; //../../utils/search.ts
//@ts-expect-error No types, expected. See: https://github.com/ading2210/libcurl.js for docs on how to use. const libcurl = await import('@utils/libcurl');
import { libcurl } from "libcurl.js-new/bundled";
let libcurlClient: boolean = false;
type Suggestion = { type Suggestion = {
phrase: string; phrase: string;
}; };
@ -81,18 +78,16 @@ import { VERSION } from "astro:env/client";
return proxyUrl; return proxyUrl;
} }
} }
function uv(iframe: HTMLIFrameElement, term: string) { async function uv(iframe: HTMLIFrameElement, term: string) {
initSw().then((init) => { const conn = await loadProxyScripts();
settings.marketPlaceSettings.handlePlugins(init.sw).then(() => { await setTransport(conn, localStorage.getItem(Settings.ProxySettings.transport) as string);
setTransport(init.conn, localStorage.getItem(Settings.ProxySettings.transport) as string).then(async () => { const sw = await initSw();
await settings.marketPlaceSettings.handlePlugins(sw);
iframe.classList.remove("hidden"); iframe.classList.remove("hidden");
const url = await proxy(term, false); const url = await proxy(term, false);
if (url) { if (url) {
iframe.src = url as string; iframe.src = url;
} }
});
});
});
} }
async function rh(iframe: HTMLIFrameElement, term: string) { async function rh(iframe: HTMLIFrameElement, term: string) {
iframe.classList.remove("hidden"); iframe.classList.remove("hidden");
@ -134,12 +129,6 @@ import { VERSION } from "astro:env/client";
}); });
input?.addEventListener("input", async function () { input?.addEventListener("input", async function () {
omnibox.innerHTML = ""; omnibox.innerHTML = "";
if (!libcurlClient) {
await libcurl.load_wasm();
libcurl.set_websocket(WispServerURLS.default);
console.debug("Libucurl ready?", libcurl.ready);
libcurlClient = true;
}
const value = input?.value; const value = input?.value;
input.classList.remove("rounded-b-2xl"); input.classList.remove("rounded-b-2xl");
omnibox.classList.remove("hidden"); omnibox.classList.remove("hidden");
@ -148,10 +137,11 @@ import { VERSION } from "astro:env/client";
omnibox.classList.add("hidden"); omnibox.classList.add("hidden");
} }
if (value.length >= 3) { if (value.length >= 3) {
const resp = await libcurl.fetch( await libcurl.client.initLibcurl();
`https://api.duckduckgo.com/ac?q=${encodeURIComponent(value)}&format=json` const data = await libcurl.client.fetchFromLibcurl(
); `https://api.duckduckgo.com/ac?q=${encodeURIComponent(value)}&format=json`,
const data = await resp.json(); 'json'
) as [];
const filteredData = data.slice(0,8); //Trim to only about 8 results. Any more and our omnibox dies const filteredData = data.slice(0,8); //Trim to only about 8 results. Any more and our omnibox dies
if (filteredData) { if (filteredData) {
omnibox.innerHTML = ""; omnibox.innerHTML = "";

28
src/utils/libcurl.ts Normal file
View file

@ -0,0 +1,28 @@
//helper for libcurl as we have to use it in multiple locations and we don't want to re-download the WASM every time
//@ts-expect-error No types, expected. See: https://github.com/ading2210/libcurl.js for docs on how to use.
import { libcurl } from "libcurl.js-new/bundled";
import { WispServerURLS } from "@utils/settings/index";
let clientExists: boolean = false;
async function initLibcurl() {
if (!clientExists) {
await libcurl.load_wasm();
libcurl.set_websocket(WispServerURLS.default);
console.debug("Libcurl ready?", libcurl.ready);
clientExists = true;
}
}
type fetchType = "json" | "text"
async function fetchFromLibcurl(url: string, type: fetchType): Promise<string | [] | {}> {
const res = await libcurl.fetch(url);
const data = type === "json" ? await res.json() : await res.text();
return data;
}
const client = {
initLibcurl,
fetchFromLibcurl
}
export { client };

View file

@ -4,6 +4,7 @@ function loadProxyScripts() {
//wrap everything in a promise to avoid race conditions //wrap everything in a promise to avoid race conditions
return new Promise<BareMuxConnection>((resolve) => { return new Promise<BareMuxConnection>((resolve) => {
const conn = new BareMuxConnection("/baremux/worker.js"); const conn = new BareMuxConnection("/baremux/worker.js");
if (typeof __uv$config !== 'undefined') { return resolve(conn) };
const uvBundle = document.createElement("script"); const uvBundle = document.createElement("script");
uvBundle.src = "/uv/uv.bundle.js"; uvBundle.src = "/uv/uv.bundle.js";
uvBundle.defer = true; uvBundle.defer = true;
@ -41,26 +42,17 @@ function setTransport(conn: BareMuxConnection, transport?: string) {
}); });
} }
type SWInitResolve = {
sw: ServiceWorkerRegistration,
conn: BareMuxConnection
}
function initSw() { function initSw() {
//this is wrapped in a promise to mostly solve the bare-mux v1 problems //this is wrapped in a promise to mostly solve the bare-mux v1 problems
return new Promise<SWInitResolve>((resolve) => { return new Promise<ServiceWorkerRegistration>((resolve) => {
if ("serviceWorker" in navigator) { if ("serviceWorker" in navigator) {
navigator.serviceWorker.ready.then(async (reg) => { navigator.serviceWorker.ready.then(async (reg) => {
console.debug("Service worker ready!"); console.debug("Service worker ready!");
const conn = await loadProxyScripts(); resolve(reg);
const resolveVal: SWInitResolve = {
sw: reg,
conn: conn
}
resolve(resolveVal);
}); });
navigator.serviceWorker.register("/sw.js", { scope: "/" }); navigator.serviceWorker.register("/sw.js", { scope: "/" });
} }
}); });
} }
export { initSw, setTransport }; export { initSw, setTransport, loadProxyScripts };

View file

@ -77,6 +77,7 @@ const marketPlaceSettings = {
handlePlugins: function(worker: never | ServiceWorkerRegistration) { handlePlugins: function(worker: never | ServiceWorkerRegistration) {
return new Promise<void>((resolve) => { return new Promise<void>((resolve) => {
const plugins = JSON.parse(localStorage.getItem(Settings.PluginSettings.plugins) as string) || []; const plugins = JSON.parse(localStorage.getItem(Settings.PluginSettings.plugins) as string) || [];
const swPlugins: SWPlugin[] = [];
if (plugins.length === 0) { if (plugins.length === 0) {
console.log('Plugin length is not greater then 0. Resolving.'); console.log('Plugin length is not greater then 0. Resolving.');
return resolve(); return resolve();
@ -84,18 +85,22 @@ const marketPlaceSettings = {
plugins.forEach(async (plugin: Plugin) => { plugins.forEach(async (plugin: Plugin) => {
if (plugin.type === "page") { if (plugin.type === "page") {
const pluginScript = await fetch(`/packages/${plugin.name}/${plugin.src}`).then((res) => res.text()); const pluginScript = await fetch(`/packages/${plugin.name}/${plugin.src}`).then((res) => res.text());
console.log(`Plugin: ${plugin.name} has the following: ${pluginScript}`);
const script = eval(pluginScript); const script = eval(pluginScript);
const inject = await script() as unknown as SWPlugin; const inject = await script() as unknown as SWPlugin;
if (plugin.remove) { if (plugin.remove) {
const idx = plugins.indexOf(plugin.name); const idx = plugins.indexOf(plugin.name);
worker.active?.postMessage([{remove: true, host: inject.host, html: inject.html, injectTo: inject.injectTo}] as SWPlugin[]); swPlugins.splice(idx, 1);
swPlugins.push({remove: true, host: inject.host, html: inject.html, injectTo: inject.injectTo});
plugins.splice(idx, 1); plugins.splice(idx, 1);
localStorage.setItem(Settings.PluginSettings.plugins, JSON.stringify(plugins)); localStorage.setItem(Settings.PluginSettings.plugins, JSON.stringify(plugins));
} }
else { else {
worker.active?.postMessage([{host: inject.host, html: inject.html, injectTo: inject.injectTo}] as SWPlugin[]); swPlugins.push({host: inject.host, html: inject.html, injectTo: inject.injectTo});
console.log(swPlugins);
} }
//only resolve AFTER we have postMessaged to the SW. //only resolve AFTER we have postMessaged to the SW.
worker.active?.postMessage(swPlugins);
resolve(); resolve();
} }
}); });