Skip to content

Commit

Permalink
Revert "Fix SrcSet & CSS issues (#148)"
Browse files Browse the repository at this point in the history
This reverts commit 0315701.
  • Loading branch information
Percslol committed Oct 27, 2024
1 parent 92d9075 commit 6e36ac9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 70 deletions.
44 changes: 16 additions & 28 deletions src/rewrite/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,36 +87,24 @@ class HTML extends EventEmitter {
return ast;
}
wrapSrcset(str, meta = this.ctx.meta) {
const regex = /(.*?)\s\d+\.?\d?[xyhw].?/g
const match = str.matchAll(regex);
var matched = false;

for (const point of match) {
matched = true;
str = str.replace(point[1], this.ctx.rewriteUrl(point[1], meta));
};

if (matched !== true) {
str = this.ctx.rewriteUrl(str, meta);
};

return str;
return str
.split(',')
.map((src) => {
const parts = src.trimStart().split(' ');
if (parts[0]) parts[0] = this.ctx.rewriteUrl(parts[0], meta);
return parts.join(' ');
})
.join(', ');
}
unwrapSrcset(str, meta = this.ctx.meta) {
const regex = /(.*?)\s\d+\.?\d?[xyhw].?/g
const match = str.matchAll(regex);
var matched = false;

for (const point of match) {
matched = true;
str = str.replace(point[1], this.ctx.sourceUrl(point[1], meta));
};

if (matched !== true) {
str = this.ctx.sourceUrl(str, meta);
};

return str;
return str
.split(',')
.map((src) => {
const parts = src.trimStart().split(' ');
if (parts[0]) parts[0] = this.ctx.sourceUrl(parts[0], meta);
return parts.join(' ');
})
.join(', ');
}
static parse = parse;
static parseFragment = parseFragment;
Expand Down
62 changes: 20 additions & 42 deletions src/uv.handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,6 @@ function __uvHook(window) {
case 'SCRIPT':
event.data.value = __uv.js.source(event.data.value);
break;
case 'STYLE':
event.data.value = __uv.sourceCSS(event.data.value);
break;
default:
event.data.value = __uv.sourceHtml(event.data.value);
}
Expand Down Expand Up @@ -680,26 +677,23 @@ function __uvHook(window) {
},
});

client.element.hookProperty(
[HTMLImageElement, HTMLSourceElement],
'srcset',
{
get: (target, that) => {
return (
client.element.getAttribute.call(
that,
__uv.attributePrefix + '-attr-srcset'
) || target.call(that)
);
},
set: (target, that, [val]) => {
client.element.setAttribute.call(
client.element.hookProperty([HTMLImageElement], 'srcset', {
get: (target, that) => {
return (
client.element.getAttribute.call(
that,
__uv.attributePrefix + '-attr-srcset',
val
);
target.call(that, __uv.html.wrapSrcset(val.toString()));
},
__uv.attributePrefix + '-attr-srcset'
) || target.call(that)
);
},
set: (target, that, [val]) => {
client.element.setAttribute.call(
that,
__uv.attributePrefix + '-attr-srcset',
val
);
target.call(that, __uv.html.wrapSrcset(val.toString()));
},
});

client.element.hookProperty(HTMLScriptElement, 'integrity', {
Expand Down Expand Up @@ -798,30 +792,14 @@ function __uvHook(window) {
});

client.node.on('getTextContent', (event) => {
switch (event.that.tagName) {
case 'SCRIPT':
event.data.value = __uv.js.source(event.data.value);
break;
case 'STYLE':
event.data.value = __uv.sourceCSS(event.data.value);
break;
default:
// Interferes with HTML Character Entities.
// event.data.value = __uv.sourceHtml(event.data.value);
if (event.that.tagName === 'SCRIPT') {
event.data.value = __uv.js.source(event.data.value);
}
});

client.node.on('setTextContent', (event) => {
switch (event.that.tagName) {
case 'SCRIPT':
event.data.value = __uv.js.rewrite(event.data.value);
break;
case 'STYLE':
event.data.value = __uv.rewriteCSS(event.data.value);
break;
default:
// Interferes with HTML Character Entities.
// event.data.value = __uv.rewriteHtml(event.data.value);
if (event.that.tagName === 'SCRIPT') {
event.data.value = __uv.js.rewrite(event.data.value);
}
});

Expand Down

0 comments on commit 6e36ac9

Please sign in to comment.