I need to push whatever I have done
This commit is contained in:
parent
4d4ebf2d09
commit
ff7eb81e87
9 changed files with 118 additions and 69 deletions
10
database_assets/com.nebula.test-2/index.js
Normal file
10
database_assets/com.nebula.test-2/index.js
Normal 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;
|
||||
10
database_assets/com.nebula.test/index.js
Normal file
10
database_assets/com.nebula.test/index.js
Normal 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;
|
||||
24
public/sw.js
24
public/sw.js
|
|
@ -5,26 +5,20 @@ const uv = new UVServiceWorker();
|
|||
|
||||
//where we handle our plugins!!!
|
||||
self.addEventListener("message", function(event) {
|
||||
//console.log(event.data);
|
||||
if (uv.config.inject === undefined) {
|
||||
uv.config.inject = [];
|
||||
}
|
||||
console.log(event.data);
|
||||
uv.config.inject = [];
|
||||
//loop over the required data (we don't verify here as types will take care of us :D)
|
||||
event.data.forEach((data) => {
|
||||
if (data.remove) {
|
||||
if (uv.config.inject.find(({ host }) => host === data.host)) {
|
||||
const idx = uv.config.inject.indexOf(data.host);
|
||||
uv.config.inject.splice(idx, 1);
|
||||
}
|
||||
const idx = uv.config.inject.indexOf(data.host);
|
||||
uv.config.inject.splice(idx, 1);
|
||||
}
|
||||
else {
|
||||
if (!uv.config.inject.find(({ host }) => host === data.host)) {
|
||||
uv.config.inject.push({
|
||||
host: data.host,
|
||||
html: data.html,
|
||||
injectTo: data.injectTo
|
||||
});
|
||||
}
|
||||
uv.config.inject.push({
|
||||
host: data.host,
|
||||
html: data.html,
|
||||
injectTo: data.injectTo
|
||||
});
|
||||
}
|
||||
});
|
||||
console.log(uv.config.inject);
|
||||
|
|
|
|||
|
|
@ -73,6 +73,28 @@ async function setupDB(db: ModelStatic<CatalogModel>) {
|
|||
tags: ["Theme", "Simple", "Dark", "Retro"],
|
||||
payload: "retro.css",
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -11,17 +11,15 @@ export const prerender = true;
|
|||
<iframe id="chango" class="w-full h-full"></iframe>
|
||||
</Layout>
|
||||
<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 { pageLoad } from "@utils/events";
|
||||
pageLoad(async () => {
|
||||
const iframe = document.getElementById("chango") as HTMLIFrameElement;
|
||||
if (iframe) {
|
||||
initSw().then((init) => {
|
||||
setTransport(init.conn, localStorage.getItem(Settings.ProxySettings.transport) as string).then(async () => {
|
||||
iframe.src = __uv$config!.prefix + __uv$config.encodeUrl!("https://radon.games");
|
||||
});
|
||||
});
|
||||
}
|
||||
const conn = await loadProxyScripts();
|
||||
await setTransport(conn, localStorage.getItem(Settings.ProxySettings.transport) as string);
|
||||
await initSw().then(() => {
|
||||
if (iframe) return iframe.src = __uv$config!.prefix + __uv$config.encodeUrl!("https://radon.games");
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -46,21 +46,18 @@ import { VERSION } from "astro:env/client";
|
|||
</div>
|
||||
</Layout>
|
||||
<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 { RammerheadEncode } from "@rubynetwork/rammerhead-browser";
|
||||
import { SupportedSites } from "@utils/siteSupport";
|
||||
import {
|
||||
WispServerURLS,
|
||||
SearchEngines,
|
||||
Settings,
|
||||
cloak,
|
||||
settings
|
||||
} from "@utils/settings/index";
|
||||
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.
|
||||
import { libcurl } from "libcurl.js-new/bundled";
|
||||
let libcurlClient: boolean = false;
|
||||
const libcurl = await import('@utils/libcurl');
|
||||
type Suggestion = {
|
||||
phrase: string;
|
||||
};
|
||||
|
|
@ -81,18 +78,16 @@ import { VERSION } from "astro:env/client";
|
|||
return proxyUrl;
|
||||
}
|
||||
}
|
||||
function uv(iframe: HTMLIFrameElement, term: string) {
|
||||
initSw().then((init) => {
|
||||
settings.marketPlaceSettings.handlePlugins(init.sw).then(() => {
|
||||
setTransport(init.conn, localStorage.getItem(Settings.ProxySettings.transport) as string).then(async () => {
|
||||
iframe.classList.remove("hidden");
|
||||
const url = await proxy(term, false);
|
||||
if (url) {
|
||||
iframe.src = url as string;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
async function uv(iframe: HTMLIFrameElement, term: string) {
|
||||
const conn = await loadProxyScripts();
|
||||
await setTransport(conn, localStorage.getItem(Settings.ProxySettings.transport) as string);
|
||||
const sw = await initSw();
|
||||
await settings.marketPlaceSettings.handlePlugins(sw);
|
||||
iframe.classList.remove("hidden");
|
||||
const url = await proxy(term, false);
|
||||
if (url) {
|
||||
iframe.src = url;
|
||||
}
|
||||
}
|
||||
async function rh(iframe: HTMLIFrameElement, term: string) {
|
||||
iframe.classList.remove("hidden");
|
||||
|
|
@ -134,12 +129,6 @@ import { VERSION } from "astro:env/client";
|
|||
});
|
||||
input?.addEventListener("input", async function () {
|
||||
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;
|
||||
input.classList.remove("rounded-b-2xl");
|
||||
omnibox.classList.remove("hidden");
|
||||
|
|
@ -147,11 +136,12 @@ import { VERSION } from "astro:env/client";
|
|||
input.classList.add("rounded-b-2xl");
|
||||
omnibox.classList.add("hidden");
|
||||
}
|
||||
if (value.length >= 3) {
|
||||
const resp = await libcurl.fetch(
|
||||
`https://api.duckduckgo.com/ac?q=${encodeURIComponent(value)}&format=json`
|
||||
);
|
||||
const data = await resp.json();
|
||||
if (value.length >= 3) {
|
||||
await libcurl.client.initLibcurl();
|
||||
const data = await libcurl.client.fetchFromLibcurl(
|
||||
`https://api.duckduckgo.com/ac?q=${encodeURIComponent(value)}&format=json`,
|
||||
'json'
|
||||
) as [];
|
||||
const filteredData = data.slice(0,8); //Trim to only about 8 results. Any more and our omnibox dies
|
||||
if (filteredData) {
|
||||
omnibox.innerHTML = "";
|
||||
|
|
|
|||
28
src/utils/libcurl.ts
Normal file
28
src/utils/libcurl.ts
Normal 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 };
|
||||
|
|
@ -4,6 +4,7 @@ function loadProxyScripts() {
|
|||
//wrap everything in a promise to avoid race conditions
|
||||
return new Promise<BareMuxConnection>((resolve) => {
|
||||
const conn = new BareMuxConnection("/baremux/worker.js");
|
||||
if (typeof __uv$config !== 'undefined') { return resolve(conn) };
|
||||
const uvBundle = document.createElement("script");
|
||||
uvBundle.src = "/uv/uv.bundle.js";
|
||||
uvBundle.defer = true;
|
||||
|
|
@ -41,26 +42,17 @@ function setTransport(conn: BareMuxConnection, transport?: string) {
|
|||
});
|
||||
}
|
||||
|
||||
type SWInitResolve = {
|
||||
sw: ServiceWorkerRegistration,
|
||||
conn: BareMuxConnection
|
||||
}
|
||||
function initSw() {
|
||||
//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) {
|
||||
navigator.serviceWorker.ready.then(async (reg) => {
|
||||
console.debug("Service worker ready!");
|
||||
const conn = await loadProxyScripts();
|
||||
const resolveVal: SWInitResolve = {
|
||||
sw: reg,
|
||||
conn: conn
|
||||
}
|
||||
resolve(resolveVal);
|
||||
resolve(reg);
|
||||
});
|
||||
navigator.serviceWorker.register("/sw.js", { scope: "/" });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export { initSw, setTransport };
|
||||
export { initSw, setTransport, loadProxyScripts };
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ const marketPlaceSettings = {
|
|||
handlePlugins: function(worker: never | ServiceWorkerRegistration) {
|
||||
return new Promise<void>((resolve) => {
|
||||
const plugins = JSON.parse(localStorage.getItem(Settings.PluginSettings.plugins) as string) || [];
|
||||
const swPlugins: SWPlugin[] = [];
|
||||
if (plugins.length === 0) {
|
||||
console.log('Plugin length is not greater then 0. Resolving.');
|
||||
return resolve();
|
||||
|
|
@ -84,18 +85,22 @@ const marketPlaceSettings = {
|
|||
plugins.forEach(async (plugin: Plugin) => {
|
||||
if (plugin.type === "page") {
|
||||
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 inject = await script() as unknown as SWPlugin;
|
||||
if (plugin.remove) {
|
||||
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);
|
||||
localStorage.setItem(Settings.PluginSettings.plugins, JSON.stringify(plugins));
|
||||
}
|
||||
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.
|
||||
worker.active?.postMessage(swPlugins);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue