mirror of
https://github.com/titaniumnetwork-dev/Ultraviolet.git
synced 2025-05-16 04:50:01 -04:00
Almost done!
This commit is contained in:
parent
da5c0c88b1
commit
355e87dd21
13 changed files with 262 additions and 38 deletions
|
@ -10,6 +10,7 @@ class StyleApi extends EventEmitter {
|
||||||
this.cssStyleProto = this.CSSStyleDeclaration.prototype || {};
|
this.cssStyleProto = this.CSSStyleDeclaration.prototype || {};
|
||||||
this.getPropertyValue = this.cssStyleProto.getPropertyValue || null;
|
this.getPropertyValue = this.cssStyleProto.getPropertyValue || null;
|
||||||
this.setProperty = this.cssStyleProto.setProperty || null;
|
this.setProperty = this.cssStyleProto.setProperty || null;
|
||||||
|
this.cssText - ctx.nativeMethods.getOwnPropertyDescriptors(this.cssStyleProto, 'cssText');
|
||||||
this.urlProps = ['background', 'backgroundImage', 'borderImage', 'borderImageSource', 'listStyle', 'listStyleImage', 'cursor'];
|
this.urlProps = ['background', 'backgroundImage', 'borderImage', 'borderImageSource', 'listStyle', 'listStyleImage', 'cursor'];
|
||||||
this.dashedUrlProps = ['background', 'background-image', 'border-image', 'border-image-source', 'list-style', 'list-style-image', 'cursor'];
|
this.dashedUrlProps = ['background', 'background-image', 'border-image', 'border-image-source', 'list-style', 'list-style-image', 'cursor'];
|
||||||
this.propToDashed = {
|
this.propToDashed = {
|
||||||
|
@ -45,6 +46,24 @@ class StyleApi extends EventEmitter {
|
||||||
return event.target.call(event.that, event.data.property, event.data.value);
|
return event.target.call(event.that, event.data.property, event.data.value);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
overrideCssText() {
|
||||||
|
this.ctx.overrideDescriptor(this.cssStyleProto, 'cssText', {
|
||||||
|
get: (target, that) => {
|
||||||
|
const event = new HookEvent({ value: target.call(that) }, target, that);
|
||||||
|
this.emit('getCssText', event);
|
||||||
|
|
||||||
|
if (event.intercepted) return event.returnValue;
|
||||||
|
return event.data.value;
|
||||||
|
},
|
||||||
|
set: (target, that, [ val ]) => {
|
||||||
|
const event = new HookEvent({ value: val }, target, that);
|
||||||
|
this.emit('setCssText', event);
|
||||||
|
|
||||||
|
if (event.intercepted) return event.returnValue;
|
||||||
|
return event.target.call(event.that, event.data.value);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export default StyleApi;
|
export default StyleApi;
|
|
@ -36,6 +36,12 @@ server.on('request', (req, res) => {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (req.url.startsWith('/uv.config.js')) {
|
||||||
|
res.writeHead(200, { "Content-Type": "application/javascript" });
|
||||||
|
createUVFileStream('uv.config.js').pipe(res);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
if (req.url.startsWith(config.prefix)) {
|
if (req.url.startsWith(config.prefix)) {
|
||||||
res.writeHead(200, { "Content-Type": "text/html" });
|
res.writeHead(200, { "Content-Type": "text/html" });
|
||||||
createReadStream(path.join(__dirname, './load.html')).pipe(res);
|
createReadStream(path.join(__dirname, './load.html')).pipe(res);
|
||||||
|
@ -49,7 +55,7 @@ server.on('upgrade', (req, socket, head) => {
|
||||||
if (!bare.route_upgrade(req, socket, head)) socket.end();
|
if (!bare.route_upgrade(req, socket, head)) socket.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen(3030);
|
server.listen(443);
|
||||||
|
|
||||||
function createUVFileStream(file) {
|
function createUVFileStream(file) {
|
||||||
return createReadStream(
|
return createReadStream(
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<script>
|
<script>
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
navigator.serviceWorker.register('/uv.sw.js', {
|
navigator.serviceWorker.register('/uv.sw.js', {
|
||||||
scope: '/sw/'
|
scope: '/sw/',
|
||||||
});
|
});
|
||||||
navigator.serviceWorker.ready.then(() => {
|
navigator.serviceWorker.ready.then(() => {
|
||||||
location.reload()
|
location.reload()
|
||||||
|
|
73
example/static/index.css
Normal file
73
example/static/index.css
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
@import url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,300;0,400;0,500;1,300;1,400&display=swap');
|
||||||
|
|
||||||
|
* {
|
||||||
|
font-family: Roboto;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
background: #131a3f;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
min-height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logo-wrapper {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
margin-top: 13%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logo {
|
||||||
|
width: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logo-wrapper .text {
|
||||||
|
font-size: 75px;
|
||||||
|
font-family: "Roboto";
|
||||||
|
color: #FFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer {
|
||||||
|
margin-top: auto;
|
||||||
|
width: 93%;
|
||||||
|
align-self: center;
|
||||||
|
height: 80px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: left;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer a , footer span {
|
||||||
|
margin: 0 15px;
|
||||||
|
text-decoration: none;
|
||||||
|
color: #FFF;
|
||||||
|
font-size: 15px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
footer a:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
form {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
form input {
|
||||||
|
background: none;
|
||||||
|
font-family: inherit;
|
||||||
|
padding: 0px 17px;
|
||||||
|
height: 48px;
|
||||||
|
border: 1px solid rgb(255, 255, 255, .2);
|
||||||
|
color: var(--text-color);
|
||||||
|
border-radius: 3px;
|
||||||
|
outline: none;
|
||||||
|
width: 435px;
|
||||||
|
margin-top: 5px;
|
||||||
|
border-radius: 50px;
|
||||||
|
color: #FFF;
|
||||||
|
}
|
|
@ -1,17 +1,25 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/idb@7/build/umd.js"></script>
|
|
||||||
<script src="uv.bundle.js"></script>
|
<link href="index.css" rel="stylesheet">
|
||||||
<script src="uv.handler.js"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Testing</h1>
|
|
||||||
<iframe src="/"></iframe>
|
<div class="logo-wrapper">
|
||||||
<script>
|
<img src="uv.png" class="logo">
|
||||||
//console.log(__uv$get(window, 'postMessage', __uv) !== __uv$get(parent, 'postMessage', __uv));
|
<div class="text">Ultraviolet</div>
|
||||||
const frame = document.querySelector('iframe').contentWindow;
|
</div>
|
||||||
addEventListener('message', e => console.log(e.source.postMessage !== window.postMessage));
|
<form>
|
||||||
</script>
|
<input placeholder="Search the web">
|
||||||
|
</form>
|
||||||
|
<footer>
|
||||||
|
<a href="https://github.com/titaniumnetwork-dev">Titanium Network</a>
|
||||||
|
<a href="https://github.com/tomphttp">TOMP</a>
|
||||||
|
<a href="https://github.com/titaniumnetwork-dev/Ultraviolet">GitHub</a>
|
||||||
|
|
||||||
|
<a href="" style="margin-left: auto">License</a>
|
||||||
|
<span>Ultraviolet 2022</span>
|
||||||
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
BIN
example/static/uv.png
Normal file
BIN
example/static/uv.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
|
@ -43,6 +43,7 @@ class HTML extends _events_js__WEBPACK_IMPORTED_MODULE_0__["default"] {
|
||||||
this.iterate(ast, fn, options);
|
this.iterate(ast, fn, options);
|
||||||
return (0,parse5__WEBPACK_IMPORTED_MODULE_1__.serialize)(ast);
|
return (0,parse5__WEBPACK_IMPORTED_MODULE_1__.serialize)(ast);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
console.log(e);
|
||||||
return str;
|
return str;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -35773,7 +35774,7 @@ function injectHead(ctx) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function createInjection(handler = '/uv.handler.js', bundle = '/uv.bundle.js', cookies = '', referrer = '') {
|
function createInjection(handler = '/uv.handler.js', bundle = '/uv.bundle.js', config = '/uv.config.js', cookies = '', referrer = '') {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
tagName: 'script',
|
tagName: 'script',
|
||||||
|
@ -35784,7 +35785,13 @@ function createInjection(handler = '/uv.handler.js', bundle = '/uv.bundle.js', c
|
||||||
value: `window.__uv$cookies = atob("${btoa(cookies)}");\nwindow.__uv$referrer = atob("${btoa(referrer)}");`
|
value: `window.__uv$cookies = atob("${btoa(cookies)}");\nwindow.__uv$referrer = atob("${btoa(referrer)}");`
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
attrs: [],
|
attrs: [
|
||||||
|
{
|
||||||
|
name: '__uv-script',
|
||||||
|
value: '1',
|
||||||
|
skip: true,
|
||||||
|
}
|
||||||
|
],
|
||||||
skip: true,
|
skip: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -35792,7 +35799,12 @@ function createInjection(handler = '/uv.handler.js', bundle = '/uv.bundle.js', c
|
||||||
nodeName: 'script',
|
nodeName: 'script',
|
||||||
childNodes: [],
|
childNodes: [],
|
||||||
attrs: [
|
attrs: [
|
||||||
{ name: 'src', value: bundle, skip: true }
|
{ name: 'src', value: bundle, skip: true },
|
||||||
|
{
|
||||||
|
name: '__uv-script',
|
||||||
|
value: '1',
|
||||||
|
skip: true,
|
||||||
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -35800,9 +35812,27 @@ function createInjection(handler = '/uv.handler.js', bundle = '/uv.bundle.js', c
|
||||||
nodeName: 'script',
|
nodeName: 'script',
|
||||||
childNodes: [],
|
childNodes: [],
|
||||||
attrs: [
|
attrs: [
|
||||||
{ name: 'src', value: handler, skip: true }
|
{ name: 'src', value: config, skip: true },
|
||||||
|
{
|
||||||
|
name: '__uv-script',
|
||||||
|
value: '1',
|
||||||
|
skip: true,
|
||||||
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
tagName: 'script',
|
||||||
|
nodeName: 'script',
|
||||||
|
childNodes: [],
|
||||||
|
attrs: [
|
||||||
|
{ name: 'src', value: handler, skip: true },
|
||||||
|
{
|
||||||
|
name: '__uv-script',
|
||||||
|
value: '1',
|
||||||
|
skip: true,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -38861,6 +38891,7 @@ class StyleApi extends _events_js__WEBPACK_IMPORTED_MODULE_0__["default"] {
|
||||||
this.cssStyleProto = this.CSSStyleDeclaration.prototype || {};
|
this.cssStyleProto = this.CSSStyleDeclaration.prototype || {};
|
||||||
this.getPropertyValue = this.cssStyleProto.getPropertyValue || null;
|
this.getPropertyValue = this.cssStyleProto.getPropertyValue || null;
|
||||||
this.setProperty = this.cssStyleProto.setProperty || null;
|
this.setProperty = this.cssStyleProto.setProperty || null;
|
||||||
|
this.cssText - ctx.nativeMethods.getOwnPropertyDescriptors(this.cssStyleProto, 'cssText');
|
||||||
this.urlProps = ['background', 'backgroundImage', 'borderImage', 'borderImageSource', 'listStyle', 'listStyleImage', 'cursor'];
|
this.urlProps = ['background', 'backgroundImage', 'borderImage', 'borderImageSource', 'listStyle', 'listStyleImage', 'cursor'];
|
||||||
this.dashedUrlProps = ['background', 'background-image', 'border-image', 'border-image-source', 'list-style', 'list-style-image', 'cursor'];
|
this.dashedUrlProps = ['background', 'background-image', 'border-image', 'border-image-source', 'list-style', 'list-style-image', 'cursor'];
|
||||||
this.propToDashed = {
|
this.propToDashed = {
|
||||||
|
@ -38896,6 +38927,24 @@ class StyleApi extends _events_js__WEBPACK_IMPORTED_MODULE_0__["default"] {
|
||||||
return event.target.call(event.that, event.data.property, event.data.value);
|
return event.target.call(event.that, event.data.property, event.data.value);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
overrideCssText() {
|
||||||
|
this.ctx.overrideDescriptor(this.cssStyleProto, 'cssText', {
|
||||||
|
get: (target, that) => {
|
||||||
|
const event = new _hook_js__WEBPACK_IMPORTED_MODULE_1__["default"]({ value: target.call(that) }, target, that);
|
||||||
|
this.emit('getCssText', event);
|
||||||
|
|
||||||
|
if (event.intercepted) return event.returnValue;
|
||||||
|
return event.data.value;
|
||||||
|
},
|
||||||
|
set: (target, that, [ val ]) => {
|
||||||
|
const event = new _hook_js__WEBPACK_IMPORTED_MODULE_1__["default"]({ value: val }, target, that);
|
||||||
|
this.emit('setCssText', event);
|
||||||
|
|
||||||
|
if (event.intercepted) return event.returnValue;
|
||||||
|
return event.target.call(event.that, event.data.value);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (StyleApi);
|
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (StyleApi);
|
||||||
|
@ -39020,6 +39069,7 @@ class Ultraviolet {
|
||||||
this.meta.origin ||= '';
|
this.meta.origin ||= '';
|
||||||
this.bundleScript = options.bundleScript || '/uv.bundle.js';
|
this.bundleScript = options.bundleScript || '/uv.bundle.js';
|
||||||
this.handlerScript = options.handlerScript || '/uv.handler.js';
|
this.handlerScript = options.handlerScript || '/uv.handler.js';
|
||||||
|
this.configScript = options.handlerScript || '/uv.config.js';
|
||||||
this.meta.url ||= this.meta.base || '';
|
this.meta.url ||= this.meta.base || '';
|
||||||
this.codec = Ultraviolet.codec;
|
this.codec = Ultraviolet.codec;
|
||||||
this.html = new _html_js__WEBPACK_IMPORTED_MODULE_0__["default"](this);
|
this.html = new _html_js__WEBPACK_IMPORTED_MODULE_0__["default"](this);
|
||||||
|
|
9
lib/uv.config.js
Normal file
9
lib/uv.config.js
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
self.__uv$config = {
|
||||||
|
prefix: '/sw/',
|
||||||
|
bare: '/bare/',
|
||||||
|
encodeUrl: Ultraviolet.codec.xor.encode,
|
||||||
|
decodeUrl: Ultraviolet.codec.xor.decode,
|
||||||
|
handler: '/uv.handler.js',
|
||||||
|
bundle: '/uv.bundle.js',
|
||||||
|
config: '/uv.config.js'
|
||||||
|
};
|
|
@ -1,14 +1,13 @@
|
||||||
if (!self.__uv) {
|
if (!self.__uv) {
|
||||||
__uvHook(self, {
|
__uvHook(self, self.__uv$config, self.__uv$config.bare);
|
||||||
prefix: '/sw/',
|
|
||||||
encodeUrl: Ultraviolet.codec.xor.encode,
|
|
||||||
decodeUrl: Ultraviolet.codec.xor.decode,
|
|
||||||
}, '/bare/');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
async function __uvHook(window, config = {}, bare = '/bare/') {
|
async function __uvHook(window, config = {}, bare = '/bare/') {
|
||||||
if ('__uv' in window && window.__uv instanceof Ultraviolet) return false;
|
if ('__uv' in window && window.__uv instanceof Ultraviolet) return false;
|
||||||
|
|
||||||
|
if (window.document && !!window.window) {
|
||||||
|
window.document.querySelectorAll("script[__uv-script]").forEach(node => node.remove())
|
||||||
|
};
|
||||||
|
|
||||||
const worker = !window.window;
|
const worker = !window.window;
|
||||||
const master = '__uv';
|
const master = '__uv';
|
||||||
|
@ -42,6 +41,7 @@ async function __uvHook(window, config = {}, bare = '/bare/') {
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
__uv.meta.origin = location.origin;
|
__uv.meta.origin = location.origin;
|
||||||
__uv.location = client.location.emulate(
|
__uv.location = client.location.emulate(
|
||||||
(href) => {
|
(href) => {
|
||||||
|
@ -146,6 +146,7 @@ async function __uvHook(window, config = {}, bare = '/bare/') {
|
||||||
methodPrefix + 'storageObj',
|
methodPrefix + 'storageObj',
|
||||||
methodPrefix + 'url',
|
methodPrefix + 'url',
|
||||||
methodPrefix + 'modifiedStyle',
|
methodPrefix + 'modifiedStyle',
|
||||||
|
methodPrefix + 'config',
|
||||||
'Ultraviolet',
|
'Ultraviolet',
|
||||||
'__uvHook',
|
'__uvHook',
|
||||||
];
|
];
|
||||||
|
@ -403,7 +404,7 @@ async function __uvHook(window, config = {}, bare = '/bare/') {
|
||||||
|
|
||||||
if (__uv.attrs.isHtml(event.data.name)) {
|
if (__uv.attrs.isHtml(event.data.name)) {
|
||||||
event.target.call(event.that, __uv.attributePrefix + '-attr-' + event.data.name, event.data.value);
|
event.target.call(event.that, __uv.attributePrefix + '-attr-' + event.data.name, event.data.value);
|
||||||
event.data.value = __uv.rewriteHtml(event.data.value, {...__uv.meta, document: true, injectHead: __uv.createHtmlInject(__uv.handlerScript, __uv.bundleScript, __uv.cookieStr, window.location.href) });
|
event.data.value = __uv.rewriteHtml(event.data.value, {...__uv.meta, document: true, injectHead:__uv.createHtmlInject(__uv.handlerScript, __uv.bundleScript, __uv.configScript, __uv.cookieStr, window.location.href) });
|
||||||
};
|
};
|
||||||
|
|
||||||
if (__uv.attrs.isSrcset(event.data.name)) {
|
if (__uv.attrs.isSrcset(event.data.name)) {
|
||||||
|
@ -522,7 +523,7 @@ async function __uvHook(window, config = {}, bare = '/bare/') {
|
||||||
set: (target, that, [val]) => {
|
set: (target, that, [val]) => {
|
||||||
target.call(that, __uv.rewriteHtml(val, {
|
target.call(that, __uv.rewriteHtml(val, {
|
||||||
document: true,
|
document: true,
|
||||||
injectHead: __uv.createHtmlInject(__uv.handlerScript, __uv.bundleScript, __uv.cookieStr, window.location.href)
|
injectHead: __uv.createHtmlInject(__uv.handlerScript, __uv.bundleScript, __uv.configScript, __uv.cookieStr, window.location.href)
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -585,7 +586,7 @@ async function __uvHook(window, config = {}, bare = '/bare/') {
|
||||||
|
|
||||||
if (__uv.attrs.isHtml(event.data.name)) {
|
if (__uv.attrs.isHtml(event.data.name)) {
|
||||||
client.element.setAttribute.call(event.that.ownerElement, __uv.attributePrefix + '-attr-' + event.data.name, event.data.value);
|
client.element.setAttribute.call(event.that.ownerElement, __uv.attributePrefix + '-attr-' + event.data.name, event.data.value);
|
||||||
event.data.value = __uv.rewriteHtml(event.data.value, {...__uv.meta, document: true, injectHead: __uv.createHtmlInject(__uv.handlerScript, __uv.bundleScript, __uv.cookieStr, window.location.href) });
|
event.data.value = __uv.rewriteHtml(event.data.value, {...__uv.meta, document: true, injectHead:__uv.createHtmlInject(__uv.handlerScript, __uv.bundleScript, __uv.configScript, __uv.cookieStr, window.location.href) });
|
||||||
};
|
};
|
||||||
|
|
||||||
if (__uv.attrs.isSrcset(event.data.name)) {
|
if (__uv.attrs.isSrcset(event.data.name)) {
|
||||||
|
@ -599,8 +600,7 @@ async function __uvHook(window, config = {}, bare = '/bare/') {
|
||||||
client.url.on('createObjectURL', event => {
|
client.url.on('createObjectURL', event => {
|
||||||
let url = event.target.call(event.that, event.data.object);
|
let url = event.target.call(event.that, event.data.object);
|
||||||
if (url.startsWith('blob:' + location.origin)) {
|
if (url.startsWith('blob:' + location.origin)) {
|
||||||
let newUrl = 'blob:' + __uv.meta.url.origin + url.slice('blob:'.length + location.origin.length);
|
let newUrl = 'blob:' + (__uv.meta.url.href !== 'about:blank' ? __uv.meta.url.origin : window.parent.__uv.meta.url.origin) + url.slice('blob:'.length + location.origin.length);
|
||||||
|
|
||||||
__uv.blobUrls.set(newUrl, url);
|
__uv.blobUrls.set(newUrl, url);
|
||||||
event.respondWith(newUrl);
|
event.respondWith(newUrl);
|
||||||
} else {
|
} else {
|
||||||
|
@ -859,6 +859,20 @@ async function __uvHook(window, config = {}, bare = '/bare/') {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
client.style.on('setCssText', event => {
|
||||||
|
event.data.value = __uv.rewriteCSS(event.data.value, {
|
||||||
|
context: 'declarationList',
|
||||||
|
...__uv.meta
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
client.style.on('getCssText', event => {
|
||||||
|
event.data.value = __uv.sourceCSS(event.data.value, {
|
||||||
|
context: 'declarationList',
|
||||||
|
...__uv.meta
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Hooking functions & descriptors
|
// Hooking functions & descriptors
|
||||||
client.fetch.overrideRequest();
|
client.fetch.overrideRequest();
|
||||||
client.fetch.overrideUrl();
|
client.fetch.overrideUrl();
|
||||||
|
@ -900,6 +914,7 @@ async function __uvHook(window, config = {}, bare = '/bare/') {
|
||||||
client.workers.overrideImportScripts();
|
client.workers.overrideImportScripts();
|
||||||
client.workers.overridePostMessage();
|
client.workers.overridePostMessage();
|
||||||
client.style.overrideSetGetProperty();
|
client.style.overrideSetGetProperty();
|
||||||
|
client.style.overrideCssText();
|
||||||
client.navigator.overrideSendBeacon();
|
client.navigator.overrideSendBeacon();
|
||||||
client.function.overrideFunction();
|
client.function.overrideFunction();
|
||||||
client.function.overrideToString();
|
client.function.overrideToString();
|
||||||
|
@ -940,6 +955,12 @@ async function __uvHook(window, config = {}, bare = '/bare/') {
|
||||||
__uv.$get = function(that) {
|
__uv.$get = function(that) {
|
||||||
if (that === window.location) return __uv.location;
|
if (that === window.location) return __uv.location;
|
||||||
if (that === window.eval) return __uv.eval;
|
if (that === window.eval) return __uv.eval;
|
||||||
|
if (that === window.parent) {
|
||||||
|
return window.__uv$parent;
|
||||||
|
};
|
||||||
|
if (that === window.top) {
|
||||||
|
return window.__uv$top;
|
||||||
|
};
|
||||||
return that;
|
return that;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
14
lib/uv.sw.js
14
lib/uv.sw.js
|
@ -1,4 +1,5 @@
|
||||||
importScripts('/uv.bundle.js');
|
importScripts('/uv.bundle.js');
|
||||||
|
importScripts('/uv.config.js')
|
||||||
|
|
||||||
const csp = [
|
const csp = [
|
||||||
'cross-origin-embedder-policy',
|
'cross-origin-embedder-policy',
|
||||||
|
@ -63,11 +64,7 @@ const statusCode = {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
const handler = UVServiceWorker('/bare/', {
|
const handler = UVServiceWorker(__uv$config.bare, __uv$config);
|
||||||
prefix: '/sw/',
|
|
||||||
encodeUrl: Ultraviolet.codec.xor.encode,
|
|
||||||
decodeUrl: Ultraviolet.codec.xor.decode,
|
|
||||||
});
|
|
||||||
|
|
||||||
addEventListener('fetch', async event =>
|
addEventListener('fetch', async event =>
|
||||||
event.respondWith(handler(event))
|
event.respondWith(handler(event))
|
||||||
|
@ -204,7 +201,7 @@ function UVServiceWorker(bare = '/bare/', options) {
|
||||||
switch(request.destination) {
|
switch(request.destination) {
|
||||||
case 'script':
|
case 'script':
|
||||||
case 'worker':
|
case 'worker':
|
||||||
responseCtx.body = `if (!self.__uv && self.importScripts) importScripts('/uv.bundle.js', '/uv.handler.js');\n`;
|
responseCtx.body = `if (!self.__uv && self.importScripts) importScripts('${__uv$config.bundle}', '${__uv$config.config}', '${__uv$config.handler}');\n`;
|
||||||
responseCtx.body += uv.js.rewrite(
|
responseCtx.body += uv.js.rewrite(
|
||||||
await response.text()
|
await response.text()
|
||||||
);
|
);
|
||||||
|
@ -222,8 +219,9 @@ function UVServiceWorker(bare = '/bare/', options) {
|
||||||
{
|
{
|
||||||
document: true ,
|
document: true ,
|
||||||
injectHead: uv.createHtmlInject(
|
injectHead: uv.createHtmlInject(
|
||||||
scripts.handler,
|
options.handler,
|
||||||
scripts.package,
|
options.bundle,
|
||||||
|
options.config,
|
||||||
uv.cookie.serialize(cookies, uv.meta, true),
|
uv.cookie.serialize(cookies, uv.meta, true),
|
||||||
request.referrer
|
request.referrer
|
||||||
)
|
)
|
||||||
|
|
|
@ -33,6 +33,7 @@ class Ultraviolet {
|
||||||
this.meta.origin ||= '';
|
this.meta.origin ||= '';
|
||||||
this.bundleScript = options.bundleScript || '/uv.bundle.js';
|
this.bundleScript = options.bundleScript || '/uv.bundle.js';
|
||||||
this.handlerScript = options.handlerScript || '/uv.handler.js';
|
this.handlerScript = options.handlerScript || '/uv.handler.js';
|
||||||
|
this.configScript = options.handlerScript || '/uv.config.js';
|
||||||
this.meta.url ||= this.meta.base || '';
|
this.meta.url ||= this.meta.base || '';
|
||||||
this.codec = Ultraviolet.codec;
|
this.codec = Ultraviolet.codec;
|
||||||
this.html = new HTML(this);
|
this.html = new HTML(this);
|
||||||
|
|
|
@ -172,7 +172,7 @@ function injectHead(ctx) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function createInjection(handler = '/uv.handler.js', bundle = '/uv.bundle.js', cookies = '', referrer = '') {
|
function createInjection(handler = '/uv.handler.js', bundle = '/uv.bundle.js', config = '/uv.config.js', cookies = '', referrer = '') {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
tagName: 'script',
|
tagName: 'script',
|
||||||
|
@ -183,7 +183,13 @@ function createInjection(handler = '/uv.handler.js', bundle = '/uv.bundle.js', c
|
||||||
value: `window.__uv$cookies = atob("${btoa(cookies)}");\nwindow.__uv$referrer = atob("${btoa(referrer)}");`
|
value: `window.__uv$cookies = atob("${btoa(cookies)}");\nwindow.__uv$referrer = atob("${btoa(referrer)}");`
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
attrs: [],
|
attrs: [
|
||||||
|
{
|
||||||
|
name: '__uv-script',
|
||||||
|
value: '1',
|
||||||
|
skip: true,
|
||||||
|
}
|
||||||
|
],
|
||||||
skip: true,
|
skip: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -191,7 +197,12 @@ function createInjection(handler = '/uv.handler.js', bundle = '/uv.bundle.js', c
|
||||||
nodeName: 'script',
|
nodeName: 'script',
|
||||||
childNodes: [],
|
childNodes: [],
|
||||||
attrs: [
|
attrs: [
|
||||||
{ name: 'src', value: bundle, skip: true }
|
{ name: 'src', value: bundle, skip: true },
|
||||||
|
{
|
||||||
|
name: '__uv-script',
|
||||||
|
value: '1',
|
||||||
|
skip: true,
|
||||||
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -199,9 +210,27 @@ function createInjection(handler = '/uv.handler.js', bundle = '/uv.bundle.js', c
|
||||||
nodeName: 'script',
|
nodeName: 'script',
|
||||||
childNodes: [],
|
childNodes: [],
|
||||||
attrs: [
|
attrs: [
|
||||||
{ name: 'src', value: handler, skip: true }
|
{ name: 'src', value: config, skip: true },
|
||||||
|
{
|
||||||
|
name: '__uv-script',
|
||||||
|
value: '1',
|
||||||
|
skip: true,
|
||||||
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
tagName: 'script',
|
||||||
|
nodeName: 'script',
|
||||||
|
childNodes: [],
|
||||||
|
attrs: [
|
||||||
|
{ name: 'src', value: handler, skip: true },
|
||||||
|
{
|
||||||
|
name: '__uv-script',
|
||||||
|
value: '1',
|
||||||
|
skip: true,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
10
tomp/tomp.js
Normal file
10
tomp/tomp.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import http from 'http';
|
||||||
|
import { Server as Bare } from './Server.mjs';
|
||||||
|
|
||||||
|
const bare = new Bare('/');
|
||||||
|
|
||||||
|
http.createServer().on('request', (req, res) =>
|
||||||
|
bare.route_request(req, res)
|
||||||
|
).on('upgrade', (req, socket, head) =>
|
||||||
|
bare.route_upgrade(req, socket, head)
|
||||||
|
).listen(4545);
|
Loading…
Add table
Add a link
Reference in a new issue