mirror of
https://github.com/titaniumnetwork-dev/Ultraviolet.git
synced 2025-05-16 21:10:02 -04:00
export UVClient separate
This commit is contained in:
parent
fddd5cd698
commit
e502dc33ea
6 changed files with 39 additions and 15 deletions
|
@ -34,7 +34,6 @@ import {
|
|||
} from './rewrite.script.js';
|
||||
import { openDB } from 'idb';
|
||||
import parsel from './parsel.js';
|
||||
import UVClient from '../client/index.js';
|
||||
import BareClient from '@tomphttp/bare-client';
|
||||
import EventEmitter from 'events';
|
||||
|
||||
|
@ -53,6 +52,7 @@ class Ultraviolet {
|
|||
this.meta.origin ||= '';
|
||||
this.bundleScript = options.bundle || '/uv.bundle.js';
|
||||
this.handlerScript = options.handler || '/uv.handler.js';
|
||||
this.clientScript = options.client || '/uv.client.js';
|
||||
this.configScript = options.config || '/uv.config.js';
|
||||
this.meta.url ||= this.meta.base || '';
|
||||
this.codec = Ultraviolet.codec;
|
||||
|
@ -61,10 +61,6 @@ class Ultraviolet {
|
|||
this.js = new JS(this);
|
||||
this.parsel = parsel;
|
||||
this.openDB = this.constructor.openDB;
|
||||
this.client =
|
||||
typeof self !== 'undefined'
|
||||
? new UVClient(options.window || self)
|
||||
: null;
|
||||
this.master = '__uv';
|
||||
this.dataPrefix = '__uv$';
|
||||
this.attributePrefix = '__uv';
|
||||
|
|
|
@ -210,6 +210,7 @@ function injectHead(ctx) {
|
|||
function createInjection(
|
||||
handler = '/uv.handler.js',
|
||||
bundle = '/uv.bundle.js',
|
||||
client = '/uv.client.js',
|
||||
config = '/uv.config.js',
|
||||
bareData = {},
|
||||
cookies = '',
|
||||
|
@ -251,6 +252,19 @@ function createInjection(
|
|||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
tagName: 'script',
|
||||
nodeName: 'script',
|
||||
childNodes: [],
|
||||
attrs: [
|
||||
{ name: 'src', value: client, skip: true },
|
||||
{
|
||||
name: '__uv-script',
|
||||
value: '1',
|
||||
skip: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
tagName: 'script',
|
||||
nodeName: 'script',
|
||||
|
|
|
@ -5,6 +5,7 @@ self.__uv$config = {
|
|||
encodeUrl: Ultraviolet.codec.xor.encode,
|
||||
decodeUrl: Ultraviolet.codec.xor.decode,
|
||||
handler: '/uv.handler.js',
|
||||
client: '/uv.client.js',
|
||||
bundle: '/uv.bundle.js',
|
||||
config: '/uv.config.js',
|
||||
sw: '/uv.sw.js',
|
||||
|
|
|
@ -1,12 +1,21 @@
|
|||
/**
|
||||
* @typedef {typeof import("./rewrite/index.js").default} Ultraviolet
|
||||
* @typedef {import("./rewrite/index.js").default} Ultraviolet
|
||||
*/
|
||||
|
||||
/**
|
||||
* @type {typeof import("./rewrite/index.js").default}
|
||||
* @typedef {import("./client/index.js").default} UVClient
|
||||
*/
|
||||
|
||||
/**
|
||||
* @type {typeof Ultraviolet}
|
||||
*/
|
||||
const Ultraviolet = globalThis.Ultraviolet;
|
||||
|
||||
/**
|
||||
* @type {typeof UVClient}
|
||||
*/
|
||||
const UVClient = globalThis.UVClient;
|
||||
|
||||
if (!self.__uv) {
|
||||
__uvHook(self, self.__uv$config, self.__uv$config.bare);
|
||||
}
|
||||
|
@ -23,16 +32,13 @@ function __uvHook(window, config = {}, bare = '/bare/') {
|
|||
const worker = !window.window;
|
||||
const master = '__uv';
|
||||
const methodPrefix = '__uv$';
|
||||
const __uv = new Ultraviolet({
|
||||
...config,
|
||||
window,
|
||||
});
|
||||
const __uv = new Ultraviolet(config);
|
||||
|
||||
if (typeof config.construct === 'function') {
|
||||
config.construct(__uv, worker ? 'worker' : 'window');
|
||||
}
|
||||
|
||||
const { client } = __uv;
|
||||
const client = new UVClient(window);
|
||||
const {
|
||||
HTMLMediaElement,
|
||||
HTMLScriptElement,
|
||||
|
@ -538,6 +544,7 @@ function __uvHook(window, config = {}, bare = '/bare/') {
|
|||
injectHead: __uv.createHtmlInject(
|
||||
__uv.handlerScript,
|
||||
__uv.bundleScript,
|
||||
__uv.clientScript,
|
||||
__uv.configScript,
|
||||
__uv.bareData,
|
||||
__uv.cookieStr,
|
||||
|
@ -742,6 +749,7 @@ function __uvHook(window, config = {}, bare = '/bare/') {
|
|||
injectHead: __uv.createHtmlInject(
|
||||
__uv.handlerScript,
|
||||
__uv.bundleScript,
|
||||
__uv.clientScript,
|
||||
__uv.configScript,
|
||||
__uv.bareData,
|
||||
__uv.cookieStr,
|
||||
|
@ -852,6 +860,7 @@ function __uvHook(window, config = {}, bare = '/bare/') {
|
|||
injectHead: __uv.createHtmlInject(
|
||||
__uv.handlerScript,
|
||||
__uv.bundleScript,
|
||||
__uv.clientScript,
|
||||
__uv.configScript,
|
||||
__uv.bareData,
|
||||
__uv.cookieStr,
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
// This is to allow us to produce a generic bundle with no hard-coded paths.
|
||||
|
||||
/**
|
||||
* @typedef {typeof import("./rewrite/index.js").default} Ultraviolet
|
||||
* @typedef {import("./rewrite/index.js").default} Ultraviolet
|
||||
*/
|
||||
|
||||
/**
|
||||
* @type {typeof import("./rewrite/index.js").default}
|
||||
* @type {typeof Ultraviolet}
|
||||
*/
|
||||
const Ultraviolet = globalThis.Ultraviolet;
|
||||
|
||||
|
@ -178,7 +178,7 @@ class UVServiceWorker extends Ultraviolet.EventEmitter {
|
|||
switch (request.destination) {
|
||||
case 'script':
|
||||
case 'worker':
|
||||
responseCtx.body = `if (!self.__uv && self.importScripts) importScripts('${ultraviolet.bundleScript}', '${ultraviolet.configScript}', '${ultraviolet.handlerScript}');\n`;
|
||||
responseCtx.body = `if (!self.__uv && self.importScripts) importScripts('${ultraviolet.bundleScript}', '${ultraviolet.clientScript}', '${ultraviolet.configScript}', '${ultraviolet.handlerScript}');\n`;
|
||||
responseCtx.body += ultraviolet.js.rewrite(
|
||||
await response.text()
|
||||
);
|
||||
|
@ -203,6 +203,7 @@ class UVServiceWorker extends Ultraviolet.EventEmitter {
|
|||
injectHead: ultraviolet.createHtmlInject(
|
||||
ultraviolet.handlerScript,
|
||||
ultraviolet.bundleScript,
|
||||
ultraviolet.clientScript,
|
||||
ultraviolet.configScript,
|
||||
this.bareClient.data,
|
||||
ultraviolet.cookie.serialize(
|
||||
|
|
|
@ -14,6 +14,9 @@ const config = {
|
|||
bundle: fileURLToPath(
|
||||
new URL('./src/rewrite/index.js', import.meta.url)
|
||||
),
|
||||
client: fileURLToPath(
|
||||
new URL('./src/client/index.js', import.meta.url)
|
||||
),
|
||||
handler: fileURLToPath(new URL('./src/uv.handler.js', import.meta.url)),
|
||||
sw: fileURLToPath(new URL('./src/uv.sw.js', import.meta.url)),
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue